Answer the question
In order to leave comments, you need to log in
Uncompilable source code - Erroneous sym type: java.util.Date?
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package example;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.Statement;
import org.apache.commons.codec.digest.DigestUtils;
import java.util.Date;
/**
*
* @author User
*/
public class Example {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
System.out.println("Java Правит Интернетом!");
System.out.println(md5Apache("Java Правит Интернетом!"));
try{
String url = "jdbc:mysql://localhost/test?serverTimezone=Europe/Moscow";
String username = "root";
String password = "root";
Class.forName("com.mysql.cj.jdbc.Driver").getDeclaredConstructor().newInstance();
try (Connection conn = DriverManager.getConnection(url, username, password)){
System.out.println("Connection to Store DB succesfull!");
Statement statement = conn.createStatement();
String pass = md5Apache("root");
java.util.Date date = java.util.Date();
String sql = "INSERT users(nickname,email,password,reg_date) VALUES ('i-rinat','[email protected]',?,?)";
PreparedStatement preparedStatement = conn.prepareStatement(sql);
preparedStatement.setString(1, pass);
preparedStatement.setInt(2, date);
int rows = preparedStatement.executeUpdate();
System.out.printf("Added %d rows", rows);
}
}
catch(Exception ex){
System.out.println("Connection failed...");
System.out.println(ex);
}
}
public static String md5Apache(String st) {
String md5Hex = DigestUtils.md5Hex(st);
return md5Hex;
}
}
Answer the question
In order to leave comments, you need to log in
here is the answer, only here the date + time goes into the database, and in this code only the date time is for some reason 00:00:00
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package example;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.Statement;
import java.time.LocalDate;
import java.time.ZoneId;
import org.apache.commons.codec.digest.DigestUtils;
import java.util.*;
/**
*
* @author User
*/
public class Example {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
System.out.println("Java Правит Интернетом!");
System.out.println(md5Apache("root"));
try{
String url = "jdbc:mysql://localhost/test?serverTimezone=Europe/Moscow";
String username = "root";
String password = "root";
Class.forName("com.mysql.cj.jdbc.Driver").getDeclaredConstructor().newInstance();
try (Connection conn = DriverManager.getConnection(url, username, password)){
System.out.println("Connection to Store DB succesfull!");
Statement statement = conn.createStatement();
String pass = md5Apache("root");
LocalDate date = LocalDate.now( ZoneId.of( "Europe/Moscow" ) );
String sql = "INSERT users(nickname,email,password,reg_date) VALUES ('i-rinat','[email protected]',?,?)";
PreparedStatement preparedStatement = conn.prepareStatement(sql);
preparedStatement.setString(1, pass);
preparedStatement.setDate(2, java.sql.Date.valueOf(date));
int rows = preparedStatement.executeUpdate();
System.out.printf("Added %d rows", rows);
}
}
catch(Exception ex){
System.out.println("Connection failed...");
System.out.println(ex);
}
}
public static String md5Apache(String st) {
String md5Hex = DigestUtils.md5Hex(st);
return md5Hex;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question