Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2003
    Posts
    28

    Unanswered: Why do I get this SQLException?

    Hello!

    Im doing a jsp-solution with mysql.
    I'm using a "Bean" that do all "SELECT" "INSERT" etc.

    My problem is:
    if I want to update a row a call on the method "setUpdate()"which looks like:

    ("key" is my primarykey and it's a "varchar" )
    --------------------------- Method -------------------------------------------
    public void setUpdate(String i) throws IOException{
    String nr=i;
    String update="UPDATE tider SET fut1='"+getNamntag()+"', eut1='"+getNamntag2()+"', fut2='"+getMednamntag()+"', eut2='"+getMednamntag2()+"',grupput='"+getGrupput( )+"', ledig="+0+" WHERE key = '"+nr+"'";
    try{
    Class.forName(driverName);
    }
    catch(ClassNotFoundException cfn){

    System.out.println(cfn);
    }

    try{
    Connection con = DriverManager.getConnection(fileURL,"", "");
    Statement updateStatement=con.createStatement();
    System.out.println(update);
    int noOfRows=updateStatement.executeUpdate(update);
    }

    catch(SQLException sqe){
    System.out.println(sqe);
    }
    }

    -----------------------------------------------------------------------------
    The problem is that I get this SQLException:

    --------------------------SQLException----------------------------------
    java.sql.SQLException: Syntax error or access violation, message from server: "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 'key = '3'' at line 1"
    -----------------------------------------------------------------------------

    If I print my Query it looks like:

    UPDATE tider SET fut1='test', eut1='test', fut2='test', eut2='tws',grupput='1', ledig=0 WHERE key = '3'

    Isn't that correct?

    I really can't figure it out why I get this Exception.

    Thanks for helping me!

    // Digital_storm

  2. #2
    Join Date
    Jul 2003
    Posts
    35
    Hi,

    You might find your answer here...

    http://www.mysql.com/doc/en/Reserved_words.html

    KEY is a reserved word for MySQL.

    Cheers,
    Ash

  3. #3
    Join Date
    Dec 2003
    Posts
    28

    Re:

    Hello!

    Thank you very much! I'll test to change my columnname.

    Regards // MiMa

    Originally posted by asherh
    Hi,

    You might find your answer here...

    http://www.mysql.com/doc/en/Reserved_words.html

    KEY is a reserved word for MySQL.

    Cheers,
    Ash

Posting Permissions

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