Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Problem with Java/MySQL query...

  1. #1
    Junior Member
    Join Date
    Nov 2010
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Problem with Java/MySQL query...

    I seem to be getting an error

    ERROR: 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 '' at line 1

    try{
                   con = DriverManager.getConnection(url+dbName,userName,password);
                      System.out.println("Connected to the database");
                   PreparedStatement pst = con.prepareStatement("INSERT INTO accounts(username, accessLevel, password) VALUES (?,?,AES_ENCRYPT=('"+passwordE+"','enigma')");
                   pst.setString(1, jTextField1.getText());
                   pst.setInt(2, accessLevel);
                   pst.executeUpdate();
                            con.close();
                              System.out.println("Disconnected from database");
                                    new Menu().setVisible(true);
                                    this.dispose();
                 } catch (SQLException e) {System.err.println("ERROR: " + e.getMessage()); }
             }


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Problem with Java/MySQL query...

    Your SQL syntax is incorrect. Make sure the SQL you are passing to the PreparedStatement is correct SQL syntax (for example, AES_ENCRYPT is typically called without the equals sign - should also make use of the PreparedStatement and rather than string concatenate, use the '?' for the encryption variables)

  3. #3
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Problem with Java/MySQL query...

    Moved thread to - JDBC & Databases
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

Similar Threads

  1. java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    By i4ba1 in forum JDBC & Databases
    Replies: 2
    Last Post: August 23rd, 2011, 12:41 PM
  2. Java.jar and Mysql.jar
    By kurt-hardy in forum Java Theory & Questions
    Replies: 1
    Last Post: January 27th, 2011, 09:48 AM
  3. Java Applet and MySQL
    By Terillius in forum JDBC & Databases
    Replies: 4
    Last Post: August 21st, 2010, 10:05 PM
  4. Connectivity problem:MySQL and Java
    By Pragya in forum JDBC & Databases
    Replies: 2
    Last Post: January 22nd, 2010, 03:58 AM
  5. Use of Unicode 5.1 in MySQL DB with Java
    By Desert Fox in forum JDBC & Databases
    Replies: 2
    Last Post: November 12th, 2008, 08:29 AM