• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can't update database?

 
raymond yadao
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have a program in jdbc. i compiled it and its okay. but when i try to run it, an error occurred :
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in
INSERT INTO statement.
at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcStatement.execute(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcStatement.executeUpdate(Unknown Source)
at DataManipulation.main(DataManipulation.java:16)
--------------------------------------------------------------
import java.sql.*;
class DataManipulation
{
public static void main(String args[])
{
String url="jdbc dbc:mysource";
String query="SELECT eno,fname,lname FROM employee";
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection myConnection=DriverManager.getConnection(url,"javauser","hotjava");
Statement myStatement=myConnection.createStatement();
myStatement.executeUpdate("insert into student" + "VALUES('s7','malouvy','que',21)");
ResultSet rs=myStatement.executeQuery(query);
while (rs.next()) {
String eno=rs.getString("studno");
String fname=rs.getString("fname");
String lname=rs.getString("lname");

System.out.println(eno);
System.out.println(fname);
System.out.println(lname);
}
myConnection.close();
}
catch(java.lang.Exception e)
{ e.printStackTrace();}
}
}
 
Adrian Yan
Ranch Hand
Posts: 688
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You fogot the space between your student and values.
"insert into student" + "\\add space here VALUES('s7','malouvy','que',21)"
also, I think you need to use the escape character for single quote. \'
 
raymond yadao
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i tried your suggestions but still i got the same error. why is this so?
 
Rani Mukherjee
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mr. Raymond,
I got the same error when there was no table in the database. So, create a table by name "employee" with the specified columns & try the same. I hope you get the output this time.
Rani
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could be many reasons... are there 4 columns in the table? Are the first three really strings and the last an int? Are you sure you the columns in the correct order? Can you run the statement stand-alone outside of a java program?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic