Results 1 to 4 of 4
Like Tree2Likes
  • 2 Post By Tolls

Thread: been trying to save to an sql table

  1. #1
    smacker is offline Member
    Join Date
    Jan 2011
    Posts
    46
    Rep Power
    0

    Default been trying to save to an sql table

    hello , i'm trying to make a save button
    the only thing it does is change the money row on a specific player

    PHP Code:
        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
            // save
              try {
                Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/casinodb", "root", "root");
                Statement stmt = con.createStatement();  
                int rs = stmt.executeUpdate("UPDATE games SET money="+c.money+"WHERE id="+c.id);
              }
              catch (Exception e) {
                System.out.println("Bad Connection " + e.getMessage());
            }
        }                                        
    
        /**
    in the int rs line it gives the exception :
    Bad Connection You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'id=1' at line 1

    any ideas on what's wrong here ? sould be working i think
    connection and server working properly

    thanks to all the helpers !

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: been trying to save to an sql table

    Build the SQL and print it in the line before the update call:
    Java Code:
    String sql = "UPDATE games SET money="+c.money+"WHERE id="+c.id;
    System.out.println(sql);
    int rs = stmt.executeUpdate(sql);
    I think you'll spot the problem then.

    This is a prime case, here, of using a PreparedStatement, by the way, which might have helped you spot the error earlier.
    PhHein and SurfMan like this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    SurfMan's Avatar
    SurfMan is online now Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,095
    Rep Power
    4

    Default Re: been trying to save to an sql table

    "what" + "do" + "you" + "think" + "this" + "line" + "looks + "like" + "when" + "you" + "print" + "it" ?

  4. #4
    smacker is offline Member
    Join Date
    Jan 2011
    Posts
    46
    Rep Power
    0

    Default Re: been trying to save to an sql table

    ahhhhhhhhhh, cools
    all about the spaces
    didn't see that one coming
    hehe
    thanks a lot!

Similar Threads

  1. Replies: 2
    Last Post: 04-03-2013, 05:33 PM
  2. Replies: 3
    Last Post: 02-23-2012, 10:30 AM
  3. Replies: 1
    Last Post: 09-27-2011, 07:06 AM
  4. How can i save the data Internally(auto save)
    By Rama Koti Reddy in forum AWT / Swing
    Replies: 2
    Last Post: 11-01-2010, 09:31 PM
  5. Replies: 1
    Last Post: 01-08-2010, 07:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •