how can i fetch date type of data from oracle database?
database
Collapse
X
-
1.) You said "date variable i am taking as Date object ". But you haveThat is a string not a date.Code:String date= "25-jun-2012";
2.) Don't ever use Statement. Use PreparedStateme nt instead because
a.)PreparedStat ement will cache the compiled query on the database and so will be faster for multiple invocations
b.)PreparedStat ement protects against SQL injection.
3.) You should create a java.sql.Date object to set as the parameter in your prepared statement. You change the String to a Date using the SimpleDateForma t class, something like
Code:date = new SimpleDateFormat("MM-dd-yyyy").parse("25-06-2012"); PreparedStatement ps = connection.prepareStatement(sql); ps.setDate(1, new java.sql.Date(date.getTime()));Comment
Comment