am using java servlet to connect to mysql.
am trying to alter a value in table 1 [userdata], containing the value gameID. then i want to delete the row in another table[gamedata] where gamenumber == gameID.
have tried it reusing the same statement and with seperate statements. any help apprciated...
<code>
public void deleteGame(HttpServletRequest req, HttpServletResponse res, int gameID, String theUsername)
throws ServletException, IOException {
PrintWriter out = new PrintWriter(res.getOutputStream(), true);
try{
Class.forName("org.gjt.mm.mysql.Driver");
Connection theConnection = DriverManager.getConnection(url, user, pass);
Statement theStatement=null;
ResultSet theResult;
String Query="";
theStatement=theConnection.createStatement();
Query = "SELECT game1,game2,game3 FROM userdata WHERE name = '"+theUsername+"'";
theResult=theStatement.executeQuery(Query);
theStatement.close();//Close statement
if(theResult.getInt(1)==gameID)
Query = "UPDATE userdata SET game1=0 WHERE name='"+theUsername+"'";
else
if(theResult.getInt(2)==gameID)
Query = "UPDATE userdata SET game2=0 WHERE name='"+theUsername+"'";
else
if(theResult.getInt(3)==gameID)
Query = "UPDATE userdata SET game3=0 WHERE name='"+theUsername+"'";
theResult.close(); //Close result set
if(!Query.equals(""))
{
//Gets here but never executes statement
theStatement=theConnection.createStatement();
theStatement.executeUpdate(Query);
theStatement.close();//Close statement
Query="DELETE FROM gamedata WHERE gamenum ="+gameID;
theStatement=theConnection.createStatement();
theStatement.executeUpdate(Query);
theStatement.close();//Close statement
}
theConnection.close(); //Close database Connection
}catch(Exception e){}
}
</code>