Import the database jar package with the following path:
E:\oracle\product\10.1.0\Db_3\jdbc\lib\ojdbc14.jar
The table statement is as follows:
CREATE TABLE T_user (
ID int PRIMARY KEY,
Username varchar (40),
Password varchar (16),
Phone varchar (40),
Address varchar (255),
CreateDate Date
)
The JDBC code is as follows:
Public void Save () {
Connection con=db. getconnection ();
String sql= "INSERT into T_user (username,password,phone,address,createdate) VALUES (?,?,?,?,?)";
PreparedStatement ps=db. getpreparedstatement (Con,sql); Note: If you want to insert date type data into Oracle, you must use the PreparedStatement object
Try {
Ps.setstring (1,username);
Ps.setstring (2,password);
Ps.setstring (3,phone);
Ps.setstring (4,address);
Ps.settimestamp (5,new Timestamp (Createdate.gettime ()));
Ps.executeupdate ();
} catch (SQLException e) {
E.printstacktrace ();
}finally{
Db. closepreparedstatement (PS);
Db. CloseConnection (con);
}
}