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 > Why do I get this SQLException?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-11-03, 17:46
digital_storm digital_storm is offline
Registered User
 
Join Date: Dec 2003
Posts: 28
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
Reply With Quote
  #2 (permalink)  
Old 12-12-03, 05:07
asherh asherh is offline
Registered User
 
Join Date: Jul 2003
Posts: 34
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
Reply With Quote
  #3 (permalink)  
Old 12-12-03, 05:48
digital_storm digital_storm is offline
Registered User
 
Join Date: Dec 2003
Posts: 28
Re:

Hello!

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

Regards // MiMa

Quote:
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
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