Win a copy of Learn Java with Math: Using Fun Projects and Games this week in the Beginning Java forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

can't update database?

 
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();}
}
}
 
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?
 
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
 
mister krabs
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?
 
Hug your destiny! And hug this tiny ad:
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!