Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JDBC java [ cannot retrive date from sql ] why??

Have Programming Question? Ask it here!
 
 
 


junis cycilraj
java [ cannot retrive date from sql ] why??
1 Answer(s)      10 months ago
Posted in : JDBC



import java.util.Date;
import java.text.SimpleDateFormat;
import java.text.ParseException;
import java.io.*;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.DriverManager;
import java.sql.SQLException;

class count{
	String getdate,append_date, d,m,y;

	public void date_mdt()throws ParseException{
		String date="2013-12-05";
		y=date.substring(0,4);
		m=date.substring(5,7);
		d=date.substring(8,10);
		
		StringBuilder sb=new StringBuilder ();
		sb.append(d);
		sb.append("-");
		sb.append(m);
		sb.append("-");
		sb.append(y);
		sb.toString();
		getdate=sb.toString();

		SimpleDateFormat sdf=new SimpleDateFormat("dd-MM-yyyy");
Date da=sdf.parse(getdate);
String format=sdf.format(da);
	try{
		 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
		 Connection c=DriverManager.getConnection("jdbc:odbc:dbdata");
        	if(c==null){ System.out.println("no connection invaild" +c);}
		Statement st=c.createStatement();
		ResultSet rs=st.executeQuery("select amt from add where dte= "+sdf.format(da)+" ");  // why cannot I retrive data from bd even if I put correct data in it
	       if( rs.next()){
			System.out.println("found ");
		}else{
			System.out.println("not found");
		}
	
	}catch(Exception ex){System.out.println(ex);}


}
public static void main(String []sd)throws Exception{
count ob=new count();
ob.date_mdt();
}
}


Advertisement
View Answers

October 6, 2013 at 7:05 PM


Hi,

Try to print the sql on console and then run in MSAccess.

I think there is date format error.

Just try the format:

01-Jan-2013 in the sql.

Thanks



Related Tutorials/Questions & Answers:
 

 

 

DMCA.com