
how to insert date in database? i need coding for that

import java.sql.*;
class InsertDate{
public static void main(String[] args){
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root" );
Statement pstmt = conn.createStatement();
java.sql.Date sqlDate = new java.sql.Date(new java.util.Date().getTime());
String INSERT_RECORD = "insert into person(dob) values('"+sqlDate+"')";
pstmt.executeUpdate(INSERT_RECORD);
pstmt.close();
conn.close();
}
catch(Exception e){
e.printStackTrace();
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.