Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regarding Data Insertion

 
adeeb alexander
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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().
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic