The Artima Developer Community
Sponsored Link

Java Answers Forum
An Exception occur in my SQL

1 reply on 1 page. Most recent reply: Dec 20, 2006 1:45 PM by Tanvir Hossain

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Tanvir Hossain

Posts: 53
Nickname: tanvirtonu
Registered: Feb, 2006

An Exception occur in my SQL Posted: Dec 15, 2006 12:53 PM
Reply to this message Reply
Advertisement
My Follwing programe throws an Exception which is-java.sql.SQLException.....Data Type mismatch
in criteria expression.
In My program there are two customiazed class- 1. DBase() and 2-JDateChooser. DBase is used to connect database.JDateChooser is a class which creates a textfield with a calendar besides it. After selecting a date frm dat calendar it shows the date in MMM dd,yyyy format. It also returns the date by getDate() in dat format. I tried to get dat date and format it in dd mm yyyy format. But the above exception occurs.
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
import tools.diit.*;
import java.sql.*;
import java.text.*;
import java.util.Date;
import com.toedter.calendar.*;
 
public class SimpleDatabaseExm extends JFrame{
	
 
 JDateChooser dtc= new JDateChooser();
 JButton btn=new JButton();
 
 String tableName = "Stat";
 String primaryKey= "ID";
 
Statement stmt;
ResultSet rs;
 
Calendar cl=new GregorianCalendar();
 
SimpleDatabaseExm (){
 
stmt = new DBase().getStatement("./Data/Diit13.mdb","",""); 
 
this.setSize(300,300);
this.setLocation(300,150);	
this.getContentPane().add(dtc,BorderLayout.NORTH);
this.getContentPane().add(btn,BorderLayout.SOUTH);
 
btn.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
      
      Date stdate=dtc.getDate();
      getDate(stdate);
      
      }
    });
	
}// end constr
 
 
public static void main(String[] args) 
{ 
 SimpleDatabaseExm dbconn=new SimpleDatabaseExm(); 
 dbconn.setVisible(true); 
 
}
 
 public void refresh()
   {
			try{
					rs =stmt.executeQuery("SELECT * FROM " + tableName);
					rs.next();
			}catch(SQLException sqle){
				System.out.println("ERROR REFRESH : " + sqle);
				}
   }//End of Method refresh()
 
 
public void getDate(Date d3)
{
//refresh();	
	
SimpleDateFormat sdf = new SimpleDateFormat("dd mm yyyy");
 
 
try{
	String s=sdf.format(d3);
	
	String s3=sdf.format(new Date());
		
	System.out.println("Start date-"+ s +"End Date"+ s3);
	
	String st="INSERT INTO Stat(Year,Income) VALUES('"+s+"','"+s3+"')";
	stmt.executeUpdate(st);
	refresh();
 
   	}
   	catch(SQLException sqle)
    {  	System.out.println("ERROR DISPLAY : " + sqle); }
	
	catch(NullPointerException ex)
	{	System.out.println("Null Pointer Ex");         }
	
 
 
	
}
 
 
}
 


Tanvir Hossain

Posts: 53
Nickname: tanvirtonu
Registered: Feb, 2006

Re: An Exception occur in my SQL Posted: Dec 20, 2006 1:45 PM
Reply to this message Reply
The fields "Year" and "Income" are set as "Date/Time" format in MSAccess. My system date format is "MM dd yyyy".MSAccess also applies this(mm dd yyyy)format by default.Why does the exception occur then? PLS HELP ME.

Flat View: This topic has 1 reply on 1 page
Topic: An Exception occur in my SQL Previous Topic   Next Topic Topic: Two pages are coming one is blank and one with data when downloading a csv

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use