Date Problem oracle
hi
i want insert current date in oracle database using prepared Statement or Statement. how i can insert.
any one help me.
hi
i want insert current date in oracle database using prepared Statement or Statement. how i can insert.
any one help me.
public static String getTodayDate() {
String tmp = null;
try {
Date now = new Date(System.currentTimeMillis());
SimpleDateFormat formatter = new SimpleDateFormat ("dd-MMM-yyyy");
tmp = formatter.format(now);
}
catch (Exception nfe) {
log.debug("Error: ", nfe);
}
return tmp;
}
public void addUser(String lastName, String firstName) throws SQLException
{
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
String query = "insert into user values(UPPER(?), ?, to_date(?,'mm/dd/yyyy'),?";
con = Database.getConnection();
ps = con.prepareStatement(query);
ps.setString(1, lastName);
ps.setString(2, firstName);
ps.setString(3, lastUpdS);
ps.setString(4, lastUpdUser);
ps.execute();
} finally {
if (rs != null)
rs.close();
if (ps != null)
ps.close();
if (con != null)
con.close();
}
}
insert into <table_name> values(to_date('1998/05/31', 'yyyy/mm/dd'));
To store Current date use sysdate ..
I Hope u get it.
Try to use JDBC escape function now() instead of Oracle specfic todate().
This way your code will be more portable.
sql = "INSERT INTO USERS VALUES("
+ "'" + userName + "'" + ","
+ "'" + userPw+ "'" + ","
+ " {fn now() } )";
--
http://www.rgagnon.com/howto.html