Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
hiisikukko
Starting Member
1 Post |
Posted - 2004-07-30 : 07:58:46
|
| First sorry about broken english.I have created simple project management software with java and mysql and i have this sql related problem.Program is working fine but......this drives me crazyI hope someone even understand what i am saying :)My problem is that when I press update button those sql-clauses below will update sql database, but if there is allready information for example in normalhours field it will be replaced with new value even if I don´t give a new value in my program. What I mean is that in my program and in database there is fields normalhours, plusminushours, absence etc. And if I want to update just normalhours all other fields in database are also updated. for exsample at the moment in my database there is normalhours=10, plusminushours=3, absence=30,but if I want to update only normalhours to 5 and I don´t give any values to plusminushours and absence result is:normalhours=5, plusminushours=0, absence=0,void jButton1_actionPerformed(ActionEvent e) {if(e.getActionCommand().equals("UPDATE")){ int changes=0; //project number String proj= jTextField1.getText();//gets project number from textfield (user given) String day= jTextField2.getText(); //gets date from textfield(user given) String ab= jTextField4.getText(); //gets absence hours from textfield(user given) String plusminus = jTextField5.getText(); //gets +/-hours from textfield(user given)String update = jTextField3.getText(); //gets normalhours (user given) String sqlLause = "update hours set normalhours= '" +update+ "'" +"where proj_id = " +proj+ " and days ='" +day+"'"; String sqlLause1 = "update hours set absence= '" +ab+ "'" +"where proj_id = " +proj+ " and days ='" +day+"'"; String sqlLause2 = "update hours set plusminushours= '" +plusminus+ "'" +"where proj_id = " +proj+ " and days ='" +day+"'"; ///creates database connection! Tietokantayhteys tietokanta = new Tietokantayhteys(); changes = tietokanta.paivityskysely(sqlLause); changes = tietokanta.paivityskysely(sqlLause1); changes = tietokanta.paivityskysely(sqlLause2); if(changes>0) { JOptionPane.showMessageDialog(null, "Update successful!"); } else JOptionPane.showMessageDialog (null, "date doesn´t exixt please save!");} }I only someone could help, (It is hard to write this kind of texts in foreign language) :) |
|
|
AndrewMurphy
Master Smack Fu Yak Hacker
2916 Posts |
Posted - 2004-07-30 : 08:33:08
|
| you need to put IF conditions around the SQL executions.if update <> 0 then changes = tietokanta.paivityskysely(sqlLause);endifif ab <> 0 then changes = tietokanta.paivityskysely(sqlLause1);endifif plusminus <> 0 then changes = tietokanta.paivityskysely(sqlLause2);endifalso....when checking changes>0....you are only testing the result of the 'last update'...if updatea or updateb fails....you get no error message trapped. |
 |
|
|
|
|
|
|
|