Invalid Cursor State Error In Jsp
here for a quick overview of the site Help Center Detailed answers to any invalid cursor exception in oracle questions you might have Meta Discuss the workings and policies of [microsoft][odbc driver manager] invalid cursor state this site About Us Learn more about Stack Overflow the company Business Learn more about hiring no current row in the resultset sqlexception developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Getting Invalid cursor state(SQL exception) up vote 0 down vote favorite I have this Code Where i am inserting some values in database. I am getting an Invalid Cursor State Exception. What may be the reason ... I am first selecting some values from a table(Select statement) which i need to insert into another table. I am doing 2 insert operations over here.. <%@ 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
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up java.sql.SQLException: Invalid cursor state in my jsp page up vote 0 down vote http://stackoverflow.com/questions/10118038/getting-invalid-cursor-statesql-exception favorite i wish to create a table in which the first 3 columns are plain text but the 4th column is a column of text areas and the last column is a column of drop down lists. all the input given in these form elements is to be sent to a separate jsp page where iit will be updated in the database. here is the code i wrote
i am very sure this is not the way to handle the table elements but this is all i could come up with. please give me any ideas in the scope of jsp and html only. now, i only started learning jsp a week ago so i am very new to the concepts. this is the stack trace: type Exception report message descriptionThe server encountered an internal error () that prevented it from fulfilling this request. exception javax.servlet.ServletException: java.sql.SQLException: [Microsoft][ODBC Driver Manager] Invalid cursor state jsp jdbc share|improve this question edited Jun 4 '12 at 6:34 asked Jun 1 '12 at 11:09 Ananya Shandilya 13 I'm not sure what you're concretely asking, but I can at least suggest to throw away that book/tutorial you're currently using.details. Win a copy of Penetration Testing Basics this week in the Security forum! Post Reply Bookmark Topic Watch Topic New Topic programming https://coderanch.com/t/302619/JDBC/databases/Invalid-cursor-state-exception-resultset forums Java Java JSRs Mobile Certification Databases Caching Books Engineering Languages https://coderanch.com/t/554469/JDBC/databases/Invalid-Cursor-State-Error Frameworks Products This Site Careers Other all forums Forum: JDBC and Relational Databases Invalid cursor state exception problem from resultset abhinav singhal Greenhorn Posts: 29 posted 11 years ago Hi , For the below mentioned code I am getting the invalid cursor state when invalid cursor the query does not return any result from the database.Please let me know how to tackle this situation so that invalid cursor state can be handled private String queryLogin; private String dbUsername; private String dbPassword; Connection connection=new ForumConnection().getConnection(); ResultSet resultset=null; /* ** Writting and executing query for getting usernames and respective password from Login table */ queryLogin="select invalid cursor state * from Login where username='"+username+"';"; try { Statement statement=connection.createStatement(); resultset=statement.executeQuery(queryLogin); resultset.next(); if(resultset!=null){ /* Here the Invalid cursor state exception is thrown */ dbUsername=resultset.getString("Username"); dbPassword=resultset.getString("Password"); } } catch (SQLException e) { System.out.println(" Query problem for Login--"+e); } if(dbUsername.equals(username) && dbPassword.equals(password) ){ return true; } else{ return false; } Basically the above code takes the username and password as input string and checks itin the database.If it doesn't exists then it return false. Regards, David O'Meara Rancher Posts: 13459 I like... posted 11 years ago If the resultset is empty, rs.next will return false and you cannot read any data from it - there is nothing to read and you get an illegal cursor position because you're not 'looking' at anything. ie you should have something like this: if(resultset.next()) { /* Here the Invalid cursor state exception is thrown */ dbUsername=resultset.getString("Username"); dbPassword=resultset.getString("Password"); } The username and pasword won't be set, but that will be because the query failed. Dave Priyaa V Kumar Ranch Hand Posts: 32 posted 11
Certification Databases Caching Books Engineering Languages Frameworks Products This Site Careers Other all forums Forum: JDBC and Relational Databases Invalid Cursor State Error Nishant Vashisth Greenhorn Posts: 23 posted 5 years ago Guy i am trying to make a online test website on jsp and am using a servelet to handle the result but when i execute the code it shows a invalid cursor error and i seriously don't know what the hell is wrong help me out please !!! Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbcdbc:mydata"); ResultSet rs; PreparedStatement pst; score=0; for(int i=1;i<=num;i++) { ansgiven=request.getParameter(Integer.toString(i)); statement="select * from test where qnum = "+i ; out.print(statement) ; pst=con.prepareStatement(statement); rs=pst.executeQuery(); ans=rs.getString("answer"); if(ans.equals(ansgiven)) { score++; } } The error is in this code only !!! help me out please Fatih Keles Ranch Hand Posts: 182 posted 5 years ago Hi Nishant, You should move your cursor to the first record, then another and then another while(rs.next()){ //now you can get values from cursor } Regards, Fatih. Nishant Vashisth Greenhorn Posts: 23 posted 5 years ago i thought of that dude !! but i want to check the result of the question as per their numbers so that i could keep track of which question is answered correct !! can you help me with the full code !! Nishant Vashisth Greenhorn Posts: 23 posted 5 years ago i got it working thanks for the suggestion dude !! moderators please close this topic !! Post Reply Bookmark Topic Watch Topic New Topic Similar Threads invalid cursor type Simple problem pls help How to check record exists CLI0115E Invalid cursor state the JDBC "invalid state cursor" error All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter Contact Us | advertise | mobile view | Powered by JForum | Copyright © 1998-2016 Paul Wheaton