wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Regarding Data Insertion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Regarding Data Insertion" Watch "Regarding Data Insertion" New topic
Author

Regarding Data Insertion

adeeb alexander
Ranch Hand

Joined: May 29, 2008
Posts: 268
Hi,
i am unable to insert values from my GUI when i click add button. The Listener for the button is as follows:

add.addActionListener(new ActionListener()
{

public void actionPerformed(ActionEvent ae)
{
if(ae.getActionCommand()=="Add")
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("jdbc.odbc.addissue","library","bismillah");
PreparedStatement ps = conn.prepareStatement("INSERT INTO addissue VALUES(?,?,?,?)");

String str0 = addtf.getText();
String str1 = addtf1.getText();
String str2 = addtf2.getText();
String str3 = addtf3.getText();
ps.setInt(1,Integer.parseInt(str0));
ps.setString(2,str1);
ps.setString(3,str2);
ps.setString(4,str3);
ps.executeUpdate();
conn.close();
}
catch(Exception ce)
{
}
}
}
});
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
if(ae.getActionCommand()=="Add")


This is a bad idea as you should not compare Strings with ==. Compare with equals(...) or equalsIgnoreCase(...). If this doesn't solve your problem, then perhaps this post should be moved to the database section as it doesn't look to be a UI problem.
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Also,


There could be a SQLException or any kind of runtime exception being thrown, and it will never be printed out because of this... at least do a ce.printStackTrace().


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Regarding Data Insertion
 
Similar Threads
Garbage Collection and String Literals
JQ+ #954287145350
comparing Strings
Eligibility for Garbage Collection
regex help