File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes data insert problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "data insert problem" Watch "data insert problem" New topic
Author

data insert problem

rahul kanojia
Greenhorn

Joined: Dec 28, 2005
Posts: 5
hello

m inserting data into ms access database (code below)
and error is

java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.


plz tell me what is the problem



<html>
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>

<head>
<title>sign in</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<%
Connection conn;
conn= null;
ResultSet rs;
rs= null;

String fname= request.getParameter("fname");
String mname= request.getParameter("mname");
String lname= request.getParameter("lname");
String email= request.getParameter("email");
String phone= request.getParameter("phone");
String dob= request.getParameter("dob");
String pin= request.getParameter("pin");
String city= request.getParameter("city");
String State= request.getParameter("State");
String Country= request.getParameter("Country");
String login= request.getParameter("login");
String pass= request.getParameter("pass");
String ada= request.getParameter("ada");
String adb= request.getParameter("adb");
String adc= request.getParameter("adc");

int Flag=0;

try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println ("Driver loaded");
String myDB ="jdbc dbc river={Microsoft Access Driver (*.mdb)};DBQ=D:/Program Files/Apache Group/Tomcat 4.1/webapps/examples/jsp/project/register.mdb";
conn = DriverManager.getConnection(myDB,"","");
System.out.println ("Connection created");
Statement stmt = conn.createStatement();
String Q="select * from register where login =" + login ;
rs=stmt.executeQuery(Q);

if (rs.next())
{
Flag=1;
%>
<script language="Javascript">
{
alert("User already exist");
location.href = "register.htm";
}
</script>
<%
}
else
{
conn.close();
}

if (Flag==0)
{


Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println ("Driver loaded");
String myDOB ="jdbc dbc river={Microsoft Access Driver (*.mdb)};DBQ=D:/Program Files/Apache Group/Tomcat 4.1/webapps/examples/jsp/project/register.mdb";
conn = DriverManager.getConnection(myDOB,"","");
System.out.println ("Connection created");
Statement st = conn.createStatement();
String P=("INSERT INTO REGISTER VALUES('"+fname+"','"+mname+"','"+lname+"','"+email+"','"+phone+"','"+dob+"',"+pin+",'"+city+"','"+State+"','"+Country+"','"+login+"','"+pass+"','"+ada+"','"+adb+"','"+adc+"')");
st.executeUpdate(P);
Flag=0;
response.sendRedirect("login.htm");
}
}
catch(Exception e)
{
out.println(e);
}
finally
{
conn.close();
}

%>
</body>
</html>
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

Well, that's nice code (not really) but when the error message tells you there is a problem with your query, it would be a good idea to look at that query. Then you would probably notice that it said and you might realize that the error message means there is no column named 'bozo' in that table.
 
wood burning stoves
 
subject: data insert problem