Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Regarding Data Insertion  RSS feed

 
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)
{
}
}
}
});

 
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.
 
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().
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!