我有这个代码,我在数据库中插入一些值。我得到一个无效的光标状态异常。可能是什么原因...我首先从需要插入另一个表的表(选择语句)中选择一些值。我在这里做 2 次插入操作..
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@page import="java.sql.*"%>
<%@page import="java.util.*"%>
<%@page import="models.app.*"%>
<%-- <%@page import="MyPackage.*;"%> --%>
<%
String id = request.getParameter("employeeidname");
int offshore = Integer.parseInt(request.getParameter("offshorename"));
String email = request.getParameter("emailidname");
String profile = request.getParameter("profilename");
String empname = request.getParameter("employeenamename");
String projectname = request.getParameter("projectname");
/* HandleConnections con = new HandleConnections(); */
Connection con=null;
try{
String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
Class.forName(driver);
String db = "jdbc:odbc:Practice_Database";
con = DriverManager.getConnection(db,"","");
ResultSet rs=null;
Statement st2 =con.createStatement();
Statement st3 =con.createStatement();
Statement st = con.createStatement();
String sql1="SELECT Project_ID FROM Project_Table WHERE Project_Name = '"+projectname+"'";
rs= st2.executeQuery(sql1);
String sql ="INSERT into Emp_Product_Project_Mapping(Emp_IDFK, Project_IDFK) values('"+id+"',"+rs.getInt("Project_ID")+")";
int j = st3.executeUpdate(sql);
/* conn = con.getConnection(); */
SendMail send = new SendMail();
Generator gen1 = new Generator();
String temp = gen1.gen(8);
send.sendmail("shantanu.tomar@gmail.com", email, temp);
String sql2= "INSERT into Employee_Table(Emp_ID,F_Name,Profile,Offshore,Email,Password) values('"+id+"','"+empname+"','"+profile+"',"+offshore+",'"+email+"','"+temp+"')";
int i = st.executeUpdate(sql2);
if(i==1)
out.println("Values inserted successfully");
}
catch(Exception e){
System.out.print(e);
e.printStackTrace();
}
%>
我从中获取值的 URL 是::
http://localhost:8080/2_8_2012/jsp/Addemployeedatabase.jsp?employeeidname=A12&offshorename=2&emailidname=Mayur.Sharma@gmail.com&profilename=GL&employeenamename=Mayur&projectname=INFRASTRUCTURE
例外 ::
[Microsoft][ODBC Driver Manager] Invalid cursor statejava.sql.SQLException: [Microsoft][ODBC Driver Manager] Invalid cursor state
使用 :: 解决
while(rs.next) to retrieve values from result set...