When I try to run INSERT INTO statement, I receive
following message:
[Microsoft][ODBC Microsoft Access Driver] Characters
found after end of SQL statement.
SQL state: 37000
Error code: -3517
Thanx in advance
Simon
The whole code for the program is:
public boolean RUNSQL(Zapis zapis, int id, int nacin)
throws java.rmi.RemoteException{
try {
Connection connection = DriverManager.getConnection
("jdbc:odbc:Zapis", "", "");
connection.setAutoCommit(false);
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
if(nacin == 1)
{
Statement stmt = connection.createStatement();
String query = "INSERT INTO zapisi ("+
"agent, indeks, vrsta, velikost,
lokacija, lastnik"+
") VALUES ('"+
zapis.getAgent() + "','"+
zapis.getId() + "','"+
zapis.getVrsta() + "','"+
zapis.getVelikost() + "','"+
zapis.getLokacija() + "','"+
zapis.getLastnik() + "');'";
int result = stmt.executeUpdate(query);
stmt.close();
}
}
catch(ClassNotFoundException cnfe)
{
System.out.println("Class " + cnfe);
return false;
}
catch(SQLException i)
{
try
{
connection.rollback();
}
catch(SQLException s)
{
System.out.println("Rollback failed");
return false;
}
System.out.println("SQL exception " + i);
return false;
}
finally{
try
{
connection.commit();
connection.close();
}
catch(SQLException sqle)
{
System.out.println("Commit failed");
return false;
}
}
connection.close();
return true;
}
catch(Exception e){
System.out.println("Error connecting to database");
}
return true;
}
You have an extra semicolon after the closing parenthesis in your INSERT
statement. The line that reads
zapis.getLastnik() + ");";
should read
zapis.getLastnik() + ")";
"Simon" <simon.sauperl@.uni-mb.si> wrote in message
news:3bab01c42a56$aaa32870$a601280a@.phx.gbl...
> When I try to run INSERT INTO statement, I receive
> following message:
> [Microsoft][ODBC Microsoft Access Driver] Characters
> found after end of SQL statement.
> SQL state: 37000
> Error code: -3517
> Thanx in advance
> Simon
> The whole code for the program is:
> public boolean RUNSQL(Zapis zapis, int id, int nacin)
> throws java.rmi.RemoteException{
> try {
> Connection connection = DriverManager.getConnection
> ("jdbc:odbc:Zapis", "", "");
> connection.setAutoCommit(false);
> try{
> Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
> if(nacin == 1)
> {
> Statement stmt = connection.createStatement();
> String query = "INSERT INTO zapisi ("+
> "agent, indeks, vrsta, velikost,
> lokacija, lastnik"+
> ") VALUES ('"+
> zapis.getAgent() + "','"+
> zapis.getId() + "','"+
> zapis.getVrsta() + "','"+
> zapis.getVelikost() + "','"+
> zapis.getLokacija() + "','"+
> zapis.getLastnik() + "');'";
> int result = stmt.executeUpdate(query);
> stmt.close();
> }
> }
> catch(ClassNotFoundException cnfe)
> {
> System.out.println("Class " + cnfe);
> return false;
> }
> catch(SQLException i)
> {
> try
> {
> connection.rollback();
> }
> catch(SQLException s)
> {
> System.out.println("Rollback failed");
> return false;
> }
> System.out.println("SQL exception " + i);
> return false;
> }
> finally{
> try
> {
> connection.commit();
> connection.close();
> }
> catch(SQLException sqle)
> {
> System.out.println("Commit failed");
> return false;
> }
> }
> connection.close();
> return true;
> }
> catch(Exception e){
> System.out.println("Error connecting to database");
> }
> return true;
> }
sql
Friday, March 23, 2012
Problem with INSERT INTO statement
Labels:
access,
charactersfound,
database,
driver,
insert,
messagemicrosoftodbc,
microsoft,
mysql,
oracle,
receivefollowing,
run,
server,
sql,
statement
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment