By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,068 Members | 1,734 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,068 IT Pros & Developers. It's quick & easy.

Problem regarding JDBC

P: 1
package com.trewport.orderprocess.action;

import java.io.*;
import java.sql.*;
import java.util.*;
import java.util.Date;
import java.lang.Object;
import javax.servlet.*;
import javax.servlet.http.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import com.trewport.orderprocess.form.EditForm;
import com.trewport.orderprocess.model.EditModel;

public class EditAction extends Action
{
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception,SQLException
{

EditForm editForm=(EditForm)form;
PrintWriter out=response.getWriter();
String orderNo = editForm.getOrderNo();
String orderName = editForm.getOrderName();
String orderQuantity = editForm.getOrderQuantity();
String orderBillingDate = editForm.getOrderBillingDate();
int orderAmount = editForm.getOrderAmount();
int totalSum = editForm.getTotalSum();
String userId = editForm.getUserId();
String date= editForm.getDate();

ActionErrors errors =new ActionErrors();

PrintWriter pw=response.getWriter();

/* this is setting up of Session */
HttpSession session = request.getSession(true);
String id= session.getAttribute("user").toString();
String dat= session.getAttribute("date").toString();
String pol= session.getAttribute("orno").toString();

System.out.println(""+pol);
Connection con=null;
PreparedStatement stmt=null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:pop");
String str="update ord set orderNo=?, "+
"orderName=?, "+
"orderQuantity=?, "+
"orderBillingDate=?, "+
"orderAmount=?, "+
"totalSum=?, "+
"userId=?, "+
"date=? "+
"where orderNo=? ";

stmt=con.prepareStatement(str);

stmt.setString(1,orderNo);
stmt.setString(2,orderName);
stmt.setString(3,orderQuantity);
stmt.setString(4,orderBillingDate);
stmt.setInt(5,orderAmount);
stmt.setInt(6,totalSum);
stmt.setString(7,id);
stmt.setString(8,dat);
stmt.setString(9,pol);

int x=stmt.executeUpdate();


EditModel em = new EditModel();
em.setOrderNo(orderNo);
em.setOrderName(orderName);
em.setOrderQuantity(orderQuantity);
em.setOrderBillingDate(orderBillingDate);
em.setOrderAmount(orderAmount);
em.setTotalSum(totalSum);
em.setUserId(userId);
em.setDate(date);
em.saveToPersistentStore();
System.out.println("the record has been entered"+x);
return (mapping.findForward("success"));
}catch(Exception ee)
{
System.out.println("43 ----");
ee.printStackTrace();
}
finally
{
stmt.close();
con.close();
}
return (mapping.findForward("failure"));
}
}

for the update statement in my program its is giving this error
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in
UPDATE statement.
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc .java:6958)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java :7115)
at sun.jdbc.odbc.JdbcOdbc.SQLExecute(JdbcOdbc.java:31 50)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.execute(Jd bcOdbcPreparedState
ment.java:214)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeUpd ate(JdbcOdbcPrepare
dStatement.java:136)
at com.trewport.orderprocess.action.EditAction.execut e(EditAction.java:8
0)
at org.apache.struts.chain.commands.servlet.ExecuteAc tion.execute(Execut
eAction.java:58)
at org.apache.struts.chain.commands.AbstractExecuteAc tion.execute(Abstra
ctExecuteAction.java:67)
at org.apache.struts.chain.commands.ActionCommandBase .execute(ActionComm
andBase.java:51)
at org.apache.commons.chain.impl.ChainBase.execute(Ch ainBase.java:190)
at org.apache.commons.chain.generic.LookupCommand.exe cute(LookupCommand.
java:304)
at org.apache.commons.chain.impl.ChainBase.execute(Ch ainBase.java:190)
at org.apache.struts.chain.ComposableRequestProcessor .process(Composable
RequestProcessor.java:283)
at org.apache.struts.action.ActionServlet.process(Act ionServlet.java:191
3)

My Bsaic program is
Jan 28 '08 #1
Share this Question
Share on Google+
1 Reply


10K+
P: 13,264
1.) Please use code tags when posting code.
2.) An easy way to debug these problems is to System.out.println the sql statement before it gets executed.
Jan 28 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.