aspose file tools*
The moose likes JDBC 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
Bookmark "Insert Query Not working" Watch "Insert Query Not working" New topic
Author

Insert Query Not working

Anonymous
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(JdbcOdbc.java:6031)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:6188)
at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(JdbcOdbc.java:2494)
at sun.jdbc.odbc.JdbcOdbcStatement.execute(JdbcOdbcStatement.java:334)
at sun.jdbc.odbc.JdbcOdbcStatement.executeUpdate(JdbcOdbcStatement.java:284)
at _0002fProfileUpdate_0002ejspProfileUpdate_jsp_18._jspService(_0002fProfileUpdate_0002ejspProfileUpdate_jsp_18.java:95)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServlet$JspCountedServlet.service(JspServlet.java:130)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:282)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:429)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:500)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:405)
at org.apache.tomcat.core.Handler.service(Handler.java:287)
at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:812)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:758)
at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:213)
at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:501)
at java.lang.Thread.run(Thread.java:484)
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
Anonymous
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="java.io.*" %>

<% 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
Yogen
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Insert Query Not working