我有这个代码我在数据库中插入一些值。我收到一个无效的游标状态异常。可能是什么原因......我首先从表中选择一些值(Select语句),我需要将其插入到另一个表中。我在这里做了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...
答案 0 :(得分:0)
如果您真的想要同时执行独立语句,那么您需要多个连接对象,通常通过连接池进行管理。
请注意,并非所有驱动程序都支持每个连接多个语句,最明显的是JDBC-ODBC桥