Please help me..i m getting this error in vista...
java.sql.SQLException:General error
at sun.jdbc.odbc.createSQLException(JdbcOdbc.java:6986)
at sun.jdbc.odbc.StandardError(JdbcOdbc.java:7114)
at sun.jdbc.odbc.SqlExecDirect(JdbcOdbc.java:3110)
at sun.jdbc.odbc.JdbcOdbcStatement.execute(JdbcOdbc.java:3110)
at sun.jdbc.odbc.JdbcOdbcStatement.executeUpdate(JdbcOdbcStatement.java:288)
....etc
there are 2 code pages..one is employee registration page and the details entered in this page is sent to EmpAddServlet....

import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class EmpAddServlet extends HttpServlet
{

public void doGet(HttpServletRequest request,HttpServletResponse response)throws IOException,ServletException
	{
	PrintWriter out=response.getWriter();
	//reading parameter from html form 
	
	String emp_name=request.getParameter("emp_name");
	String emp_id=request.getParameter("emp_id");
	String emp_age=request.getParameter("emp_age");
	String dept_id=request.getParameter("dept_id");
	String emp_salary=request.getParameter("emp_salary");
	String emp_pass=request.getParameter("password");
	String emp_address=request.getParameter("add");
	String emp_ph=request.getParameter("phno");

	System.out.println("Hello!!!");

try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:dsn","","");
out.println("U have Entered:"+emp_name);
out.println("U have Entered:"+emp_address+" "+emp_ph);

/*PreparedStatement pst=con.prepareStatement("insert into emp(emp_name,emp_id,emp_age,emp_salary,dept_id,emp_pass,emp_address,emp_ph) values (?,?,?,?,?,?,?,?) ");
pst.setString(1,emp_name);
pst.setString(2,emp_id);
pst.setString(3,emp_age);
pst.setString(4,emp_salary);
pst.setString(5,dept_id);
pst.setString(6,emp_pass);
pst.setString(7,emp_address);
pst.setString(8,emp_ph);

System.out.println("Hello again!!!");

int x=pst.executeUpdate();*/

Statement st=con.createStatement();
String query="insert into emp values ('"+emp_name+"','"+emp_id+"','"+emp_age+"','"+emp_salary+"','"+dept_id+"','"+emp_pass+"','"+emp_address+"','"+emp_ph+"')";
int x=st.executeUpdate(query);

System.out.println("Hello again 2 !!!");
out.println(x+"Emp Row is updated");
System.out.println(x);
}

catch(Exception e)
{
e.printStackTrace();
System.out.println('e');
}

}


}

Recommended Answers

All 4 Replies

the above code reads values entered in employee reg page which is as follows (javascript part removed)

<body bgcolor="#CCFFCC" onLoad="cur()">
<div align="center">
<strong><font color="#FF0000" size="5">Employee Registration Form</font></strong>
<hr>

<form  name="f" action="./EmpAddServlet"  method="get" onSubmit="return validate(this);">
<div align="right"><font color=cccccc><b>Date :<%=dt%>-<%=d.getMonth()+1%>-<%=d.getYear()+1900%></font></div>

<table width="50%" height="60%" border="4" cellpadding="3" bgcolor="#99CCFF">
	
	<tr bordercolor="#99CCFF"> 
        		<td > 
			<div align="right" ><font size="3"><strong>Employee Id:</strong></font></div>
		</td>
		<td width="250"> 
			<div align="left"> 
			<input name="emp_id" type="text" value='<%//=pk.getPartnerId() %>' >
<!--onfocus="setFocus(this)">-->
			</div>
		</td>
	</tr>


	<tr bordercolor="#99CCFF"> 
        		<td > 
			<div align="right" ><font size="3"><strong>DepartmentId:</strong></font></div>
		</td>
		<td width="250"> 
			<div align="left"> 
			<input name="dept_id" type="text" value='<%//=pk.getPartnerId() %>' >
<!--onfocus="setFocus(this)">-->
			</div>
		</td>
	</tr>


		
	<tr bordercolor="#99CCFF"> 
		<td> 
			<div align="right"><font size="3"><strong>Employee Name :</strong></font></div>
		</td>
		<td> 
			<div align="left"> 
			<input name="emp_name" type="text" id="pname" onChange="return check1(this);" >
			</div>
		</td>
     	 </tr>

	


	<tr bordercolor="#99CCFF"> 
		<td> 
			<div align="right"><font size="3"><strong>Password :</strong></font></div>
		</td>
        		<td> 
			<div align="left"> 
            			<input name="password" type=password  id="password" >
          			</div>
		</td>
	</tr>

	<tr bordercolor="#99CCFF"> 
		<td> 
			<div align="right"><font size="3"><strong>Confirm Password :</strong></font></div>
		</td>
        		<td> 
			<div align="left"> 
            			<input name="Cpassword" type=password  id="Cpassword" onChange="return check2(this);">
          			</div>
		</td>
	</tr>

		


	<tr bordercolor="#99CCFF"> 
		<td> 
			<div align="right"><strong>Salary(Per Annum) :</strong></div>
		</td>
		<td> 
			<input name="emp_salary" type="text" id="ic" onChange="return check3(this);"></td>
	</tr>

	<tr bordercolor="#99CCFF"> 
		<td> 
			<div align="right"><strong>Age (in yrs) :</strong></div>
		</td>
		<td> 
			<input name="emp_age" type="text" id="age" onChange="return check5(this);"></td>
	</tr>

	

	<tr bordercolor="#99CCFF"> 
		<td> 
			<div align="right"><font size="3"><strong>Address :</strong></font></div>
		</td>
        		<td> 
		               <div align="left"> 
			<textarea name="add" id="add" cols="19" rows="5" ></textarea>
			</div>
		</td>
	</tr>

	<tr bordercolor="#99CCFF"> 
        		<td> 
			<div align="right"><font size="3"><strong>Ph No :</strong></font></div>
		</td>
        		<td> 
			<div align="left"> 
			<input name="phno" type="text" id="phno" maxlength="10" onChange="return check4(this);">
          			</div>
		</td>
      	</tr>


				

	<tr bordercolor="#99CCFF"> 
        		<td> 
			<div align="right"> 
			<input type="reset" id="sub" value="Reset">
			</div>
		</td>
        		<td> 
		               <input name="submit" type="submit" value="Submit">
		</td>
      	</tr>
    </table>
    </form>
    </div>

EmpAddServlet is a java file....I m running this on vista...is it due to vista as it doesnt support certain functionalities...This prog is running on xp with access 2003...in the database all the fields are properly named...also i m using access 2010 in vista...is there some modification in 2010 like the 2003 version does not have a username or password....hope 2010 also doesnt require any username or password...

Deleted

ok...got it...the problem was that emp_id was a primary key in the database...so exception is generated whenever user tries to insert duplicate values....and i was just inserting same test values ...lost 2 days just over this... :(

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.