I want to add a new record to access database,, but the SQL query is not applying it,, here is my Code in which i am adding data!!
public void actionPerformed(ActionEvent e) {
JButton b=(JButton)e.getSource();
if(b==c.t.addR){
String aa=Integer.toString(55);
String t=c.t.titlefield.getText();
String d=c.t.datefield.getText();
String p=c.t.progressfield.getText();
String pr=c.t.priorityfield.getText();
String s="Open";
System.out.println(t+"\t"+d+"\t"+p+"\t"+pr+"\t"+s); //error is here
try {
c.b.st.executeQuery("INSERT into Records (TaskID,Title,Deadline,Progress,Priority,Status) VALUES("+aa+"','"+t+"','"+d+"','"+p+"','"+pr+"','"+s+")");
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
Here is the error i am getting
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver]
Syntax error (missing operator) in query expression
’55’,’a’,’1′,’1′,’high’,’Open’. 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.executeQuery(Unknown Source) at
Listener.actionPerformed(Listener.java:27) at
javax.swing.AbstractButton.fireActionPerformed(Unknown Source) at
javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source) at
javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source) at
javax.swing.DefaultButtonModel.setPressed(Unknown Source) at
javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown
Source) at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source) at
javax.swing.JComponent.processMouseEvent(Unknown Source) at
java.awt.Component.processEvent(Unknown Source) at
java.awt.Container.processEvent(Unknown Source) at
java.awt.Component.dispatchEventImpl(Unknown Source) at
java.awt.Container.dispatchEventImpl(Unknown Source) at
java.awt.Component.dispatchEvent(Unknown Source) at
java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) at
java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) at
java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) at
java.awt.Container.dispatchEventImpl(Unknown Source) at
java.awt.Window.dispatchEventImpl(Unknown Source) at
java.awt.Component.dispatchEvent(Unknown Source) at
java.awt.EventQueue.dispatchEventImpl(Unknown Source) at
java.awt.EventQueue.access$400(Unknown Source) at
java.awt.EventQueue$2.run(Unknown Source) at
java.awt.EventQueue$2.run(Unknown Source) at
java.security.AccessController.doPrivileged(Native Method) at
java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown
Source) at
java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown
Source) at java.awt.EventQueue$3.run(Unknown Source) at
java.awt.EventQueue$3.run(Unknown Source) at
java.security.AccessController.doPrivileged(Native Method) at
java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown
Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at
java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown
Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at
java.awt.EventDispatchThread.run(Unknown Source)
The error has to be happening on this line:
And looking at it, it will be because you don’t have an openning and closing quote around your parameters? Try: