FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Insertion error for date values





raneez_n
I get error when i try to insert more than one date values to the table, but it execute successfully when i try with one date value.

The error i got when using more than 2 date values is:



Code:

java.sql.SQLException: [MySQL][ODBC 5.1 Driver][mysqld-5.5.15]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'From) values(100,1,_binary'2011-09-17',_binary'2011-09-18')' at line 1
   at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
   at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
   at sun.jdbc.odbc.JdbcOdbc.SQLExecute(Unknown Source)
   at sun.jdbc.odbc.JdbcOdbcPreparedStatement.execute(Unknown Source)
   at sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeUpdate(Unknown Source)
   at DateDemo.InsertDate(DateDemo.java:37)
   at DateDemo.main(DateDemo.java:65)
raneez_n
Code:
public void InsertDate(int ref,int id,Date d1,Date d2)
   {   
      Connection con=null;
      PreparedStatement ps=null;
      String query=null;
      java.sql.Date dd1=null,dd2=null;
      
      
      try
      {
      
      query="insert into new_table (Ref_No,Emp_Id,Doapp,From) values(?,?,?,?)";
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      con=DriverManager.getConnection("jdbc:odbc:date","root","1234");
      ps=con.prepareStatement(query);
      
      ps.setInt(1, ref);
      ps.setInt(2,id);
      ps.setDate(3,new java.sql.Date(d1.getTime()) );
      ps.setDate(4, new java.sql.Date(d2.getTime()));
      int i=ps.executeUpdate();
      
      }
      catch(Exception e)
      {
         e.printStackTrace();
      }
Fire Boar
"From" is an SQL statement. You must surround it in `backticks` in order for it to be interpreted as a literal field name by the SQL parser.
raneez_n
thanks a lot. It is better to avoid such field names.
Related topics
How To : Improve Your PHP Programming
C++ TUTORIAL : INTRODUCTION TO C++
MySQL statement error (got me going)
Fix this somebody please..
1st timer
insert data to mySQL database problem
PHP - Error
wrong date using time() and date()
Forum Avatar error
Image not showing
Database connection class!
Checking for values in database and displaying error page
You don't have permission to access / on this server.
404 Not Found error was encountered (PLEASE HELP!!!)
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.