java.sql.Date Comparison with oracle date
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   RAMAKRISHNAN_DILIP
Posted On:   Friday, August 10, 2001 09:14 AM

Hi, I have converted string to java.sql.Date format after parsing using the below code . String testd="10/22/1997"; SimpleDateFormat sdfinDate = new SimpleDateFormat("MM/dd/yyyy"); java.util.Date actualDate = null; java.sql.Date asql = null; try { actualDate = sdfinDate.parse(testd); asql = new java.sql.Date(actualDate.getTime()); } catch (java.text.ParseException e112) { JOptionPane.showMessageDialog(null,"Not in Date Format" ); } Now i want to compare this date with the resultset value date from oracle database . Class.forName("   More>>

Hi,
I have converted string to java.sql.Date format after parsing using the below code .

			
String testd="10/22/1997";
SimpleDateFormat sdfinDate = new SimpleDateFormat("MM/dd/yyyy");
java.util.Date actualDate = null;
java.sql.Date asql = null;

			
try
{
actualDate = sdfinDate.parse(testd);
asql = new java.sql.Date(actualDate.getTime());
}

catch (java.text.ParseException e112)
{
JOptionPane.showMessageDialog(null,"Not in Date Format" );
}





Now i want to compare this date with the resultset value date from oracle database .

			
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con3=DriverManager.getConnection(url2,"scott","tiger");
stm3=con3.createStatement();
resu3=stm3.executeQuery("select * from entrytable where year='"+asql"" ");


this query is not matching with any records ...
how to change the oracle value according to this value ?


please anyone help me.
Stuck up .    <<Less

Re: java.sql.Date Comparison with oracle date

Posted By:   Christopher_Schultz  
Posted On:   Friday, August 10, 2001 10:05 AM

That's because you are passing the whole data ("Friday August 10 2001 12:58:22 EDT") to the SQL statement. You want to get just the year from the date:




import java.util.Calendar;
.
.
.

Calendar c = new Calendar();
c.setTime(actualDate);
long year = s.get(Calendar.YEAR);
.
.
.
resu3=stm3.executeQuery("select * from entrytable where year='" + year + "'");



As always, I'll recommend that you use PreparedStatement instead of Statement. It gives you better control over your queries, and is more database independent than straight Statement use.



-chris
About | Sitemap | Contact