473,231 Members | 1,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,231 software developers and data experts.

Need help with java.sql.Date!

helpwithcode
Hi people,
I am just learning java.I have been creating a project which involves JDBC Connectivity.I find that the statements,

String string_dob=text_dob.getText();
//Converting string to date
System.out.println(string_dob);
s.Info_DOB=Date.valueOf(string_dob);



runs perfectly fine in the method insert() and throws up an illegal Exception in the method UPDATE.This is the error I get when I pass a date "1979-05-02"

Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: " 1979"
at java.lang.NumberFormatException.forInputString(Unk nown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.sql.Date.valueOf(Unknown Source)
at DateGUI.Update_Employee(DateGUI.java:225)
at DateGUI.actionPerformed(DateGUI.java:133)
at javax.swing.AbstractButton.fireActionPerformed(Unk nown Source)
at javax.swing.AbstractButton$Handler.actionPerformed (Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed (Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent( Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(U nknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unkno wn Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)


where line 225 is: s.Info_DOB=Date.valueOf(string_dob);
and line 133 is: Update_Employee();

Would appreciate if someone is able to rectify the error!
Thanks,
Wishing you a great day,
with best regards,
helpwithcode

/*@author helpwithcode
* Project Name: DATE
* File:DateGUI.java
* Objective:Creates the GUI and binds the button controls to the various Data Access Functions
*/

/*Import the various system files*/
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Date;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;


/*Declaration and definition of the class DateGUI and implementation of ActionListener to handle the button controls*/
public class DateGUI extends JFrame implements ActionListener
{


/*Declaration of the variables*/
JPanel panel = new JPanel(); // create pane content object
JLabel prompt = new JLabel(" SQL Query Test ");
JTextField text_id=new JTextField(5);
JTextField text_name=new JTextField(5);
JTextField text_dob=new JTextField(10);
JTextField text_role=new JTextField(5);
JLabel label_id=new JLabel("Employee ID:");
JLabel label_name=new JLabel("Employee NAME:");
JLabel label_dob=new JLabel("Employee DOB:");
JLabel label_role=new JLabel("Employee ROLE:");
JButton button_insert = new JButton("INSERT");
JButton button_search=new JButton("SEARCH");
JButton button_clear=new JButton("CLEAR");
JButton button_update=new JButton("UPDATE");
JButton button_delete=new JButton("DELETE");
JButton button_next=new JButton("NEXT");
JButton button_previous=new JButton("PREVIOUS");

/*Constructor for the class DateGUI*/
/*The constructor implements the GUI Interface*/
DateGUI() // the constructor
{

/*Declaration of panel and container*/
/*Container-any swing component can be made a container and all other components can be added on to it*/
super("JDBC DEMO!"); setBounds(50,50,240,200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container con = this.getContentPane(); // inherit main frame
/*JPanel is a simple container class which can group components and divide a frame into sub-frames*/
/*JPanel panel is made a container on Container con*/
con.add(panel);
/*The 'panel' is made into a Grid Layout Structure*/
panel.setLayout(new GridLayout(14,2)); // reset manager
/*All the components are added to the 'panel'*/
panel.add(label_id);
panel.add(text_id);
panel.add(label_name);
panel.add(text_name);
panel.add(label_dob);
panel.add(text_dob);
panel.add(label_role);
panel.add(text_role);
panel.add(button_insert);
panel.add(button_search);
panel.add(button_clear);
panel.add(button_update);
panel.add(button_delete);
panel.add(button_next);
panel.add(button_previous);


button_insert.addActionListener(this);
button_insert.setMnemonic('P'); setVisible(true);

button_search.addActionListener(this);
button_search.setMnemonic('P'); setVisible(true);

button_clear.addActionListener(this);
button_clear.setMnemonic('P'); setVisible(true);

button_update.addActionListener(this);
button_update.setMnemonic('P'); setVisible(true);

button_delete.addActionListener(this);
button_delete.setMnemonic('P');setVisible(true);

button_next.addActionListener(this);
button_next.setMnemonic('P');setVisible(true);

button_previous.addActionListener(this);
button_previous.setMnemonic('P');setVisible(true);


}
// now the basic event listeners

public void actionPerformed(ActionEvent ae)
{
Object source = ae.getSource();
if (source == button_insert) {// button from above example
JOptionPane.showMessageDialog(null,"I hear you!","Message Dialog",
JOptionPane.PLAIN_MESSAGE); ;// show something
Insert_Employee();
}


if (source == button_search) {// button from above example
JOptionPane.showMessageDialog(null,"I hear you!","Message Dialog",
JOptionPane.PLAIN_MESSAGE); ;// show something
Search_Employee();


}


if (source == button_clear) {// button from above example
JOptionPane.showMessageDialog(null,"I hear you!","Message Dialog",
JOptionPane.PLAIN_MESSAGE); ;// show something
Clear_Employee();


}

if (source == button_update) {// button from above example
JOptionPane.showMessageDialog(null,"I hear you!","Message Dialog",
JOptionPane.PLAIN_MESSAGE); ;// show something
Update_Employee();


}

if (source == button_delete) {// button from above example
JOptionPane.showMessageDialog(null,"I hear you!","Message Dialog",
JOptionPane.PLAIN_MESSAGE); ;// show something
Delete_Employee();
}


if (source == button_next) {// button from above example
JOptionPane.showMessageDialog(null,"I hear you!","Message Dialog",
JOptionPane.PLAIN_MESSAGE); ;// show something
Next_Employee();
}

if (source == button_previous) {// button from above example
JOptionPane.showMessageDialog(null,"I hear you!","Message Dialog",
JOptionPane.PLAIN_MESSAGE); ;// show something
Previous_Employee();
}
}
//Begin GUI Insert

void Insert_Employee()
{
DateInfo s=new DateInfo();
DateDAO dao = new DateDAO();

s.Info_Id=Integer.parseInt(text_id.getText());
s.Info_Name=text_name.getText();
s.Info_Role=text_role.getText();
String string_dob=text_dob.getText();
//Converting string to date
System.out.println(string_dob);
s.Info_DOB=Date.valueOf(string_dob);
System.out.println(s.Info_Id);
System.out.println(s.Info_Name);
System.out.println(s.Info_DOB);
System.out.println(s.Info_Role);

dao.insert(s.Info_Id, s.Info_Name, s.Info_DOB,s.Info_Role);
System.out.println(s.Info_Id);
System.out.println(s.Info_Name);
System.out.println(s.Info_DOB);
System.out.println(s.Info_Role);

}//end of GUI Insert

//Begin GUI Search

void Search_Employee()
{
DateInfo s=new DateInfo();
DateDAO dao = new DateDAO();
s.Info_Id=Integer.parseInt(text_id.getText());
s=dao.search(s.Info_Id);
text_id.setText(""+s.Info_Id);
text_name.setText(s.Info_Name);
text_dob.setText(" "+s.Info_DOB.toString());
text_role.setText(s.Info_Role);


}//end of GUI Search
//Begin GUI Clear

void Clear_Employee()
{
text_id.setText(""+0);
text_name.setText("Enter your name ");
text_dob.setText("1900-01-01 ");
text_role.setText("Enter your role ");
}


//End of GUI Clear
//Begin GUI Update
void Update_Employee()
{
DateInfo s=new DateInfo();
DateDAO dao = new DateDAO();

s.Info_Id=Integer.parseInt(text_id.getText());
s.Info_Name=text_name.getText();
s.Info_Role=text_role.getText();

String string_dob=text_dob.getText();
//Converting string to date
System.out.println(string_dob);
s.Info_DOB=Date.valueOf(string_dob);
System.out.println(s.Info_Id);
System.out.println(s.Info_Name);
System.out.println(s.Info_DOB);
System.out.println(s.Info_Role);

dao.update(s.Info_Id, s.Info_Name, s.Info_DOB,s.Info_Role);
System.out.println(s.Info_Id);
System.out.println(s.Info_Name);
System.out.println(s.Info_DOB);
System.out.println(s.Info_Role);



}



//End of GUI Update

//GUI Delete
void Delete_Employee()
{
DateInfo s=new DateInfo();
DateDAO dao = new DateDAO();
s.Info_Id=Integer.parseInt(text_id.getText());



dao.delete(s.Info_Id);
text_id.setText(" ");

text_name.setText(" ");
text_dob.setText(" ");
text_role.setText(" ");

}//end of GUI Delete

/*GUI Next_Employee()
*
*/

void Next_Employee()
{
DateInfo s=new DateInfo();
DateDAO dao = new DateDAO();
s.Info_Id=Integer.parseInt(text_id.getText());
s=dao.next(s.Info_Id);
text_id.setText(""+s.Info_Id);
text_name.setText(s.Info_Name);
text_role.setText(s.Info_Role);
text_dob.setText(""+s.Info_DOB);
}//end of Next

/*GUI Previous_Employee()
*
*/

void Previous_Employee()
{
DateInfo s=new DateInfo();
DateDAO dao = new DateDAO();
s.Info_Id=Integer.parseInt(text_id.getText());
s=dao.previous(s.Info_Id);
text_id.setText(""+s.Info_Id);
text_name.setText(s.Info_Name);
text_role.setText(s.Info_Role);
text_dob.setText(""+s.Info_DOB);
}//end of Previous

// and finally the main method
public static void main(String[] args) {
new DateGUI();

}
}
Aug 4 '07 #1
7 5304
I am enclosing the other two files for convenience.
Thanks!

/*@author helpwithcode
* Project Name: DATE
* File:DateDAO.java
* Objective:Creates a class which provides the actual data access functions, insert/update/delete/search etc. between the front end,DateGUI.java and the back end,
* the database,EmpDet
*/


/*The various files are imported here*/
import java.sql.*;
import java.sql.Date;


/*Declaration and definition of the DateDAO class*/
public class DateDAO
{
//function insert

public void insert(int id, String name, Date dob , String role)
{

/*Declaration of all the variables*/
DateInfo Specimen;
Specimen=new DateInfo();
Specimen.Info_Id=id;
Specimen.Info_Name=name;
Specimen.Info_Role=role;
Specimen.Info_DOB=dob;
System.out.println("DAO Class Printing Date"+Specimen.Info_DOB);
String url="jdbc:odbc:MyDataSource";
Connection con=null;

/*Load the SQL Server*/

try{
String driver="sun.jdbc.odbc.JdbcOdbcDriver";
Class.forName(driver).newInstance();
}

catch(Exception e){
System.out.println("Failed to load SQL Server");
return;
}

/*Establish Connection with the SQL Server and enable data transfer*/
try{
con=DriverManager.getConnection(url,"","");
Statement select=con.createStatement();
String SQLQuery="INSERT into Details(EMPLOYEE_ID,EMPLOYEE_NAME,EMPLOYEE_ROLE,EM PLOYEE_DOB)"+
"VALUES("+Specimen.Info_Id+",'"+Specimen.Info_Name +"','"+Specimen.Info_Role+"','"+Specimen.Info_DOB+ "')";
int row_count=select.executeUpdate(SQLQuery);
System.out.println(row_count +"number of rows updated");
}

catch(Exception e){
e.printStackTrace();
}
/*close Connection*/
finally{
if(con!=null){
try {con.close();}
catch(Exception e){e.printStackTrace();
}
}

}
}//end of function insert

//function search

public DateInfo search(int id )
{

/*Declaration of variables*/
DateInfo Specimen;
Specimen=new DateInfo();
Specimen.Info_Id=id;

String url="jdbc:odbc:MyDataSource";
Connection con=null;
/*Create an object of the type JDBC Driver and load the SQL Server*/
try{
String driver="sun.jdbc.odbc.JdbcOdbcDriver";
Class.forName(driver).newInstance();
}

catch(Exception e){
System.out.println("Failed to load SQL Server");

}
/*Establish Connection with the SQL Server and enable data transfer*/
try{
con=DriverManager.getConnection(url,"","");
Statement ps;
String SQLQuery="SELECT * FROM Details WHERE EMPLOYEE_ID='"+Specimen.Info_Id+"'";
ps=con.createStatement();
ResultSet hello;
hello=ps.executeQuery(SQLQuery);
while(hello.next()){


Specimen.Info_Name=hello.getString("EMPLOYEE_NAME" );
Specimen.Info_DOB=hello.getDate(3);

Specimen.Info_Role=hello.getString("EMPLOYEE_ROLE" );

}
}

catch(Exception e){
e.printStackTrace();
}
/*Close Connection*/
finally{
if(con!=null){
try {con.close();}
catch(Exception e){e.printStackTrace();
}
}
}
/*Return an object of type Specimen DateInfo which contains values obtained from the database*/
return Specimen;
}//end of function search


//begin function update

public void update(int id, String name,java.sql.Date dob, String role )
{
/*Declaration of the variables*/
DateInfo Specimen;
Specimen=new DateInfo();
Specimen.Info_Id=id;
Specimen.Info_Name=name;
Specimen.Info_DOB=dob;
Specimen.Info_Role=role;
String url="jdbc:odbc:MyDataSource";
Connection con=null;
/*Create and object of type JDBC Driver which loads the SQL Server*/
try{
String driver="sun.jdbc.odbc.JdbcOdbcDriver";
Class.forName(driver).newInstance();
}

catch(Exception e){
System.out.println("Failed to load SQL Server");
return;
}
/*Establish connection with the server using the object of type JDBC Driver and enable data transfer*/
try{
con=DriverManager.getConnection(url,"","");
Statement select=con.createStatement();
String dob_string=Specimen.Info_DOB.toString();
String SQLQuery="UPDATE Details SET EMPLOYEE_NAME="+"'"+Specimen.Info_Name+"'"+",EMPLO YEE_DOB="+"'"+Specimen.Info_DOB+"'"+",EMPLOYEE_ROL E="+"'"+Specimen.Info_Role+"'"+ "WHERE EMPLOYEE_ID="+"'"+Specimen.Info_DOB+"'";
int row_count=select.executeUpdate(SQLQuery);
System.out.println(row_count +"number of rows updated");
System.out.println("Parameter Date now is" +dob_string);
System.out.println("Parameter Date now is, in Date Format" +Specimen.Info_DOB);

}

catch(Exception e){
e.printStackTrace();
}
/*Close connection with the database*/
finally{
if(con!=null){
try {con.close();}
catch(Exception e){e.printStackTrace();
}
}

}
}//end of function update


public void delete(int id )
{
/*Declaration of the variables*/
DateInfo Specimen;
Specimen=new DateInfo();
Specimen.Info_Id=id;

String url="jdbc:odbc:MyDataSource";
Connection con=null;
/*Load the SQL Server*/
try{
String driver="sun.jdbc.odbc.JdbcOdbcDriver";
Class.forName(driver).newInstance();
}

catch(Exception e){
System.out.println("Failed to load SQL Server");

}
/*Establish Connection and obtain data access*/
try{
con=DriverManager.getConnection(url,"","");
Statement ps;
String SQLQuery="DELETE FROM Details WHERE EMPLOYEE_ID='"+Specimen.Info_Id+"'";
ps=con.createStatement();
ResultSet hello;
hello=ps.executeQuery(SQLQuery);



}

catch(Exception e){
e.printStackTrace();
}
/*Close Connection*/
finally{
if(con!=null){
try {con.close();}
catch(Exception e){e.printStackTrace();
}
}
}


}//end of function delete
/*Function Next*/
public DateInfo next(int id )
{
/*Declare the variables*/
DateInfo Specimen;
Specimen=new DateInfo();
String url="jdbc:odbc:MyDataSource";
Connection con=null;
/*Load the SQL Server*/
try{
String driver="sun.jdbc.odbc.JdbcOdbcDriver";
Class.forName(driver).newInstance();
}

catch(Exception e){
System.out.println("Failed to load SQL Server");

}
/*Establish Connection with the database and establish data access*/
try{
con=DriverManager.getConnection(url,"","");
Statement ps;
String SQLQuery="SELECT * FROM Details ";
ps=con.createStatement();
ResultSet hello;
hello=ps.executeQuery(SQLQuery);


hello.moveToCurrentRow();
int d=hello.getRow();
System.out.println(d);

while(hello.next()){
/*Point the cursor to the current record*/
Specimen.Info_Id=hello.getInt(1);
Specimen.Info_Name=hello.getString(2);
Specimen.Info_Role=hello.getString(4);
Specimen.Info_DOB=hello.getDate(3);
/*Move to the next record within the ResultSet*/
if(Specimen.Info_Id==id)
{
hello.next();
Specimen.Info_Id=hello.getInt(1);
Specimen.Info_Name=hello.getString(2);
Specimen.Info_Role=hello.getString(4);
Specimen.Info_DOB=hello.getDate(3);
/*Return the object whose variables contain the values for the next record*/
return Specimen;


}

}



}

catch(Exception e){
e.printStackTrace();
}
/*Close Connection*/
finally{
if(con!=null){
try {con.close();}
catch(Exception e){e.printStackTrace();
}
}
}
System.out.println(Specimen.Info_Id+Specimen.Info_ Name+Specimen.Info_Role);

return Specimen;
}//end of function next
/*Function Previous*/
public DateInfo previous(int id )
{
/*Declare the variables*/
DateInfo Specimen;
Specimen=new DateInfo();
String url="jdbc:odbc:MyDataSource";
Connection con=null;
/*Load the SQL Server*/
try{
String driver="sun.jdbc.odbc.JdbcOdbcDriver";
Class.forName(driver).newInstance();
}

catch(Exception e){
System.out.println("Failed to load SQL Server");

}
/*Establish Connection with the database and establish data access*/
try{
con=DriverManager.getConnection(url,"","");
Statement ps;
String SQLQuery="SELECT * FROM Details ";
ps=con.createStatement(ResultSet.TYPE_SCROLL_INSEN SITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet hello;
hello=ps.executeQuery(SQLQuery);
hello.afterLast();


while(hello.previous()){
/*Point the cursor to the current record*/
Specimen.Info_Id=hello.getInt(1);
Specimen.Info_Name=hello.getString(2);
Specimen.Info_Role=hello.getString(4);
Specimen.Info_DOB=hello.getDate(3);
/*Move to the next record within the ResultSet*/
if(Specimen.Info_Id==id)
{
hello.previous();
Specimen.Info_Id=hello.getInt(1);
Specimen.Info_Name=hello.getString(2);
Specimen.Info_Role=hello.getString(4);
Specimen.Info_DOB=hello.getDate(3);
/*Return the object whose variables contain the values for the next record*/
return Specimen;


}

}



}

catch(Exception e){
e.printStackTrace();
}
/*Close Connection*/
finally{
if(con!=null){
try {con.close();}
catch(Exception e){e.printStackTrace();
}
}
}
System.out.println(Specimen.Info_Id+Specimen.Info_ Name+Specimen.Info_Role);

return Specimen;
}//end of function previous

}//end of class


/*@author helpwithcode
* Project Name: DATE
* File:DateInfo.java
* Objective:Creates a class whose variables are used to bind the input fields to the columns in the table"Details" in the Database"EmpDet".
*/

/*The various files required are imported*/
import java.sql.Date;


/*Declaration and Definition of the Class DateInfo*/
public class DateInfo {
int Info_Id; /*Stores the EMPLOYEE_ID*/
String Info_Name,Info_Role; /*Info_Name stores the EMPLOYEE_NAME and the Info_role stores the EMPLOYEE_ROLE*/
java.sql.Date Info_DOB; /*Info_DOB stores the date of birth of the Employees-this is of the data type,'DATE'*/

public void DateInfo() /*Default Constructor*/
{
Info_Id=0;
Info_Name=null;
Info_DOB=null;
Info_Role=null;

}
public void DateInfo(int id, String name, Date dob,String role) /*Construct is called when the INSERT parameters are passed*/
{
Info_Id=id;
Info_Name=name;
Info_DOB=dob;
Info_Role=role;

}

public void DateInfo( String name,Date dob, String role) /*Constructor is called when the UPDATE parameters are passed*/
{

Info_Name=name;
Info_DOB=dob;
Info_Role=role;



}


//Getters-auto generated in Eclipse
public int getInfo_Id() {
return Info_Id;
}
public String getInfo_Name() {
return Info_Name;
}
public Date getInfo_DOB() {
return (Date) Info_DOB;
}
public String getInfo_Role() {
return Info_Role;
}

//Setters-auto generated in Eclipse
public void setInfo_Id(int info_Id) {
Info_Id = info_Id;
}
public void setInfo_Name(String info_Name) {
Info_Name = info_Name;
}
public void setInfo_DOB(Date info_DOB) {
Info_DOB = info_DOB;
}

public void setInfo_Role(String info_Role) {
Info_Role = info_Role;
}





}//end of class DataInfo

/*Database creation
create db EmpDet
Go
use EmpDet
go
CREATE TABLE DETAILS
(
EMPLOYEE_ID INT PRIMARY KEY,
EMPLOYEE_NAME CHAR(50),
EMPLOYEE_DOB DATETIME,
EMPLOYEE_ROLE CHAR(50)
)
GO

INSERT INTO DETAILS(EMPLOYEE_ID,EMPLOYEE_NAME,EMPLOYEE_DOB,EMP LOYEE_ROLE)
VALUES(1,"NAMEONE",12/12/2002,"ROLEONE")
GO


INSERT INTO DETAILS(EMPLOYEE_ID,EMPLOYEE_NAME,EMPLOYEE_DOB,EMP LOYEE_ROLE)
VALUES(2,"NAMETWO",13/01/2003,"ROLETWO")
GO

INSERT INTO DETAILS(EMPLOYEE_ID,EMPLOYEE_NAME,EMPLOYEE_DOB,EMP LOYEE_ROLE)
VALUES(3,"NAMETHREE",14/02/2004,"ROLETHREE")
GO

INSERT INTO DETAILS(EMPLOYEE_ID,EMPLOYEE_NAME,EMPLOYEE_DOB,EMP LOYEE_ROLE)
VALUES(4,"NAMEFOUR",15/03/2005,"ROLEFOUR")
GO


INSERT INTO DETAILS(EMPLOYEE_ID,EMPLOYEE_NAME,EMPLOYEE_DOB,EMP LOYEE_ROLE)
VALUES(5,"NAMEFIVE",16/04/2006,"ROLEFIVE")
GO

P.S. I have the DNS set to MyDataSource , which points to the Database EmpDet.
Insert/Search and Delete work perfectly fine.
Aug 4 '07 #2
Here is the problem:
dao.update(s.Info_Id, s.Info_Name, java.sql.Date.valueOf(string_dob),s.Info_Role);

gives the following error for the string "1979-07-09",

xception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: " 1979"
at java.lang.NumberFormatException.forInputString(Unk nown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.sql.Date.valueOf(Unknown Source)
at DateGUI.Update_Employee(DateGUI.java:233)
at DateGUI.actionPerformed(DateGUI.java:133)
at javax.swing.AbstractButton.fireActionPerformed(Unk nown Source)
at javax.swing.AbstractButton$Handler.actionPerformed (Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed (Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent( Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(U nknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unkno wn Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Aug 6 '07 #3
This is the Database Details for the problem:
CREATE DB EMPDET
GO

USE EMPDET
GO
CREATE TABLE DETAILS
(
EMPLOYEE_ID INT PRIMARY KEY,
EMPLOYEE_NAME CHAR(50),
EMPLOYEE_DOB DATETIME,
EMPLOYEE_ROLE CHAR(50)
)
GO

DNS Settings:
Database:EmpDet
DataSource:MyDataSource
Aug 7 '07 #4
r035198x
13,262 8TB
1.) Use code tags when posting code/stacktraces
2.) I suggest you debug using a debug tool or printlns. If it says the format is not valid, then chances are very good that the format is not valid. Somewhere in your code the date value is being modified into an incorrect format.
Aug 7 '07 #5
1.) Use code tags when posting code/stacktraces
2.) I suggest you debug using a debug tool or printlns. If it says the format is not valid, then chances are very good that the format is not valid. Somewhere in your code the date value is being modified into an incorrect format.

Hey r035198x,

THANKS A LOT!I JUST FOUND OUT MY MISTAKE-A VERY SIMPLE MISTAKE REALLY.
I HAD AN EXTRA SPACE IN THE TEXTBOXES(MY SEARCH METHOD ADDS AN EXTRA SPACE-DUE TO PARSING) WHICH GOT CONCATENATED WITH WHATEVER I ENTERED INTO THEM. SINCE THIS IS NOT AN ACCEPTABLE FORMAT IN DATE DATA TYPE IN JAVA, IT WAS GIVING ERRORS EVEN BEFORE THE SQL QUERY WAS CALLED.
LOGICALLY EVERYTHING WAS RIGHT, SINCE I HAD DONE THE SAME WITHOUT THE DATE AND THE UPDATE WAS WOKRING PERFECTLY!

THANKS FOR THE SUGGESTIONS THOUGH, SHALL KEEP THEM IN MIND .
Aug 7 '07 #6
Hey r035198x,

THANKS A LOT!I JUST FOUND OUT MY MISTAKE-A VERY SIMPLE MISTAKE REALLY.
I HAD AN EXTRA SPACE IN THE TEXTBOXES(MY SEARCH METHOD ADDS AN EXTRA SPACE-DUE TO PARSING) WHICH GOT CONCATENATED WITH WHATEVER I ENTERED INTO THEM. SINCE THIS IS NOT AN ACCEPTABLE FORMAT IN DATE DATA TYPE IN JAVA, IT WAS GIVING ERRORS EVEN BEFORE THE SQL QUERY WAS CALLED.
LOGICALLY EVERYTHING WAS RIGHT, SINCE I HAD DONE THE SAME WITHOUT THE DATE AND THE UPDATE WAS WOKRING PERFECTLY!

THANKS FOR THE SUGGESTIONS THOUGH, SHALL KEEP THEM IN MIND
Aug 7 '07 #7
r035198x
13,262 8TB
Hey r035198x,

THANKS A LOT!I JUST FOUND OUT MY MISTAKE-A VERY SIMPLE MISTAKE REALLY.
I HAD AN EXTRA SPACE IN THE TEXTBOXES(MY SEARCH METHOD ADDS AN EXTRA SPACE-DUE TO PARSING) WHICH GOT CONCATENATED WITH WHATEVER I ENTERED INTO THEM. SINCE THIS IS NOT AN ACCEPTABLE FORMAT IN DATE DATA TYPE IN JAVA, IT WAS GIVING ERRORS EVEN BEFORE THE SQL QUERY WAS CALLED.
LOGICALLY EVERYTHING WAS RIGHT, SINCE I HAD DONE THE SAME WITHOUT THE DATE AND THE UPDATE WAS WOKRING PERFECTLY!

THANKS FOR THE SUGGESTIONS THOUGH, SHALL KEEP THEM IN MIND
You didn't have to start a new thread for that. We don't close threads even though the issues seem to be resolved.
Also refrain from using all caps (considered shouting). The rest of the guidelines can be found here.
I'll have to delete your other thread.
Aug 7 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: James Hong | last post by:
Help please, I try to sending an email from my html page using the java applet. but it give error on most of the PC only very few work, what is the error i make the java applet show as below ...
2
by: cg_news | last post by:
In short, what I am trying to do is, based on a date, calculate the week of year (as described in ISO 8601), then calculate the first and last date in this week period and return them in the format...
4
by: Thomas Mann | last post by:
Hi, how can I make my XSLT-stylesheet insert a timestamp (date/time) into the output file ? Regards Thomas
1
by: 848lu | last post by:
hey i really need help...i got this code....basically im suppose to make a calender that allows a user to type in month and year .... and the calander displays it on the scree using...
7
by: erekose666 | last post by:
I need a java prog to do the following: Create class Date with the following capabilities: a) Output the date in multiple formats, such as: MM/DD/YYYY June 14, 2005 DDD YYYY b) Use...
3
sammyboy78
by: sammyboy78 | last post by:
I'm trying to display an array of objects using a GUI. My instructions are that the CD class and it's sublcass don't need to change I just need to modify class CDInventory to include the GUI. I'm not...
0
by: TraceyAnnison | last post by:
I wonder if you can help me - I'm new to this, and working in a project that has already been configured to work with Axis. We have a Java project built with the Spring framework, in order to...
1
by: vadala | last post by:
The requirement is to send start data and end date from java to UI (.net) for a functionality. We are setting the time in java (1.5) before handing it over to WebService (sending to UI ) in...
19
by: robtyketto | last post by:
Greetings, I have the following code below which allows the date to be added via a JDBC connection as a STRING. The value of dateString is inserted into the MS ACCESS database. What is the...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.