File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Insert Query Not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Insert Query Not working" Watch "Insert Query Not working" New topic

Insert Query Not working

Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi all,
I am working with jsp and backened MSacess. I am not able to insert into database, but other than that i am able to perform all other operations on my database.
I am encountering the following error nad i am not able to figure out why.I will really be thankful if some can answer me.
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 2.
at sun.jdbc.odbc.JdbcOdbc.createSQLException(
at sun.jdbc.odbc.JdbcOdbc.standardError(
at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(
at sun.jdbc.odbc.JdbcOdbcStatement.execute(
at sun.jdbc.odbc.JdbcOdbcStatement.executeUpdate(
at _0002fProfileUpdate_0002ejspProfileUpdate_jsp_18._jspService(
at org.apache.jasper.runtime.HttpJspBase.service(
at javax.servlet.http.HttpServlet.service(
at org.apache.jasper.servlet.JspServlet$JspCountedServlet.service(
at javax.servlet.http.HttpServlet.service(
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(
at org.apache.jasper.servlet.JspServlet.serviceJspFile(
at org.apache.jasper.servlet.JspServlet.service(
at javax.servlet.http.HttpServlet.service(
at org.apache.tomcat.core.ServletWrapper.doService(
at org.apache.tomcat.core.Handler.service(
at org.apache.tomcat.core.ServletWrapper.service(
at org.apache.tomcat.core.ContextManager.internalService(
at org.apache.tomcat.core.ContextManager.service(
at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(
at org.apache.tomcat.service.TcpWorkerThread.runIt(
at org.apache.tomcat.util.ThreadPool$
Yogen Vadnere
Ranch Hand

Joined: Sep 20, 2001
Posts: 58
If possible please post ur insert code..then we will fig out why it is not working??

Yogen Vadnere
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
this is my whole code for that and i really appreciate your quick reply.

<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="*" %>

<% String ssn1 = request.getParameter("txtSsn") ;<br /> String lastname = request.getParameter("txtLastname");<br /> String firstname=request.getParameter("txtFirstName");<br /> String email=request.getParameter("txtEmail");<br /> String gender=request.getParameter("cboGender");<br /> String degree=request.getParameter("cboDegree");<br /> String major1=request.getParameter("cboMajor1");<br /> String major2=request.getParameter("cboMajor2");<br /> String graduationdate=request.getParameter("txtGraduationDate");<br /> String authorization=request.getParameter("cboAuthorization");<br /> String jobtype=request.getParameter("cboJobType");<br /> String gpa1=request.getParameter("txtGpa");<br /> String skill=request.getParameter("txtSkills");<br /> int ssn;<br /> double gpa;<br /> String driver = "sun.jdbc.odbc.JdbcOdbcDriver";<br /> String url = "jdbc dbc:Resume"; <br /> <br /> ssn=Integer.parseInt(ssn1);<br /> gpa=Double.parseDouble(gpa1);<br /> Class.forName(driver);<br /> Connection con=null;<br /> try{<br /> con=DriverManager.getConnection(url);<br /> /*String sql=*/<br /> Statement stmt=con.createStatement();<br /> stmt.executeUpdate("insert into Profile values(ssn,'lastname','firstname','email','gender','degree','major1','major2','graduationdate','authorization','jobtype',gpa,'skill')"); <br /> stmt.close();<br /> stmt=null;<br /> }<br /> finally{<br /> if(con!=null){<br /> con.close();}<br /> }<br /> %>

Yogen Vadnere
Ranch Hand

Joined: Sep 20, 2001
Posts: 58
Hello Vikram,
I have two suggession for u, please re-registered and user ur name as per javaranch policy and second and most important do not start new topic for same question, always post and repost ur suggession and opinon in same topic.
Hope u will cooperate.
Thankx in advance
I agree. Here's the link:
subject: Insert Query Not working
jQuery in Action, 3rd edition