If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > jsp->mysql problem. statement reuse? other?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-21-04, 06:03
nogribin nogribin is offline
Registered User
 
Join Date: Apr 2004
Posts: 1
jsp->mysql problem. statement reuse? other?

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>
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On