-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDateTimeExample.java
More file actions
27 lines (22 loc) · 926 Bytes
/
DateTimeExample.java
File metadata and controls
27 lines (22 loc) · 926 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
public class DateTimeExample {
public static void main(String args[]){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("Jdbc:Odbc:mydsn","","");
java.util.Date date=new java.util.Date();
java.sql.Date sqlDate=new java.sql.Date(date.getTime());
java.sql.Timestamp sqlTime=new java.sql.Timestamp(date.getTime());
PreparedStatement ps=con.prepareStatement("insert into record (date,time) values(?,?)");
ps.setDate(1,sqlDate);
ps.setTimestamp(2,sqlTime);
ps.executeUpdate();
ps.close();
con.close();
}catch(Exception e){
e.printStackTrace();
}
}
}