Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Syntax error in insert into statement

843859Mar 11 2008 — edited Mar 11 2008
Hi,

im writing a simple program which inserts new rows to a MS access database.
im getting this exception saying syntax error
i cudn't find where is the error
when i work with select statement it works fine.
code is given below

package DB;
import java.sql.*;


public class www {
	
	static ResultSet res;
	static Connection conn=null;
	static Statement stat;
	int i=0;

	public static void main(String args[])    {
		try  {
			int x=3;
			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
			conn = DriverManager.getConnection("jdbc:odbc:LED"); 
			stat = conn.createStatement();
			
			int count = 0;
			try{
		      int c = stat.executeUpdate("INSERT INTO test1 (number,message) VALUES (3,'hello1');");
		      count = count + c;
			}
			catch(Exception ee){
				System.out.println(" its here "+ee.getStackTrace());
				ee.printStackTrace();
			}
		      stat.close();
		      conn.close();     
			}
			catch(Exception e)   {
			System.out.println("Error" +e);
			e.printStackTrace();
			}
		
		try  {
			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
			conn = DriverManager.getConnection("jdbc:odbc:LED1"); // cust is the DSN Name
			stat = conn.createStatement();
			res = stat.executeQuery("Select * from test1 where message="+"'hello'");  
			www w2=new www();    
			while(res.next())
		    w2.showRecord(res);
		    }
			catch(Exception e)   {
			System.out.println("Error" +e);
			}
		}
	public void showRecord(ResultSet res)   {
		try  {
		String w=res.getString(2);
		i=i+1;
	    System.out.println("the value at row "+i+" : "+w);
		}
		catch(Exception e)  {
		System.out.println("Error" +e);
		}
		
	        }
	        
}
exception is given below

its here [Ljava.lang.StackTraceElement;@47b480
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 DB.www.main(www.java:22)
the value at row 1 : hello



if anyone can assist pls respond,
thanks
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 8 2008
Added on Mar 11 2008
4 comments
521 views