• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

can't update database?

 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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();}
}
}
 
Ranch Hand
Posts: 688
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i tried your suggestions but still i got the same error. why is this so?
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Did you just should on me? You should read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic