Hi,
I am having problem with inserting a row into the MsAccess Database. I am getting error like
"SQLException: Occurred while performing Database Operations ---> method Main() java.sql.SQLException
: [Microsoft][ODBC Microsoft Access 97 Driver] Syntax error in INSERT INTO statement.[Microsoft][ODB
C Microsoft Access 97 Driver] Syntax error in INSERT INTO statement".
My code is as under:
please help me out.
Smitha
==========================================
package dao;
import utils.GeneralFailureException;
import dbConnection.dbConnection;
import java.util.*;
import java.sql.*;
public class GeneralExpenses {
dbConnection dbCon = new dbConnection();
public GeneralExpenses() {
super();
}
public static java.sql.Timestamp getTstamp() {
java.util.Date date = (Calendar.getInstance()).getTime();
java.sql.Timestamp tStamp = new java.sql.Timestamp(date.getTime());
System.out.println("The Time Stamp : " + tStamp);
return tStamp;
}
public void insertExpenseTable(
String sExphead, double dAmount, String sMode)
throws GeneralFailureException, SQLException, ClassNotFoundException {
String inssql = "INSERT INTO EXPENSES(tnum, date , " + sExphead + ", " + sMode + ") VALUES(?,?,?,?)";
Connection conn = null;
PreparedStatement pstmt = null;
try {
conn = dbCon.getConnection();
pstmt = conn.prepareStatement(inssql);
pstmt.setInt(1, 100);
pstmt.setTimestamp(2, getTstamp());
pstmt.setDouble(3, dAmount);
pstmt.setString(4, sMode);
pstmt.executeUpdate();
} finally {
dbCon.closeAll(pstmt, conn);
}
}
public static void main(String[] args) {
try {
GeneralExpenses ge = new GeneralExpenses();
ge.insertExpenseTable("xxxxxxx", 250.35, "yyyyyyyy");
System.out.println("worked");
} catch(ClassNotFoundException sqlex) {
System.err.print("SQLException: Occurred while performing Database Operations ---> method Main() " + sqlex);
System.err.println(sqlex.getMessage());
}
catch(SQLException sqlex) {
System.err.print("SQLException: Occurred while performing Database Operations ---> method Main() " + sqlex);
System.err.println(sqlex.getMessage());
} catch(GeneralFailureException e) {
System.err.print("GeneralFailureException: Occurred while Establishing Connection ---> method getConnection() " + e);
System.err.println(e.getMessage());
} catch(Exception e) {
System.err.print("GeneralFailureException: Occurred while Establishing Connection ---> method getConnection() " + e);
System.err.println(e.getMessage());
}
}
}