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.

[142 byte] By [Java_Jsp_servleta] at [2007-11-27 11:48:17]
# 1

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();

}

}

skp71a at 2007-7-29 18:18:21 > top of Java-index,Java Essentials,New To Java...
# 2

insert into <table_name> values(to_date('1998/05/31', 'yyyy/mm/dd'));

To store Current date use sysdate ..

I Hope u get it.

solvina at 2007-7-29 18:18:21 > top of Java-index,Java Essentials,New To Java...
# 3

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

RealHowToa at 2007-7-29 18:18:21 > top of Java-index,Java Essentials,New To Java...