Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Prepares Statement : No ResultSet was produced  RSS feed

 
vikram nalagampalli
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting the following error if i am trying to execute this code.
javax.servlet.ServletException: No ResultSet was produced
WHAT DOES THIS MEAN? CANT I USE PREPARE STATEMENT WITH UPDATE QUERIES?.

<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.lang.*" %>
<%@ page import="java.lang.String" %>
<%@ page import="java.io.*" %>
<%@ page import="resume1.Resume" %>
<%@ page session="true"%>
<jsp:useBean id="r"
class="resume1.Resume" scope="request"/>

<%String driver =
"sun.jdbc.odbc.JdbcOdbcDriver";
String url = "jdbc dbc:Resume";
String userId =
(String)session.getAttribute("Ssn");
Class.forName(driver);
Connection con=null;
try{
con=DriverManager.getConnection(url);


String st= "UPDATE resume SET
StreetAddress=?,City=?,State=?,Zip=?,Coun
try=?,Email=?,Phone=?,Fax=?,Objective=?,S
chool1=?,City1=?,State1=?,GraduationYear1
=?,Major1=?,Gpa1=?,School2=?,City2=?,Stat
e2=?,GraduationYear2=?,Major2=?,Gpa2=?,Em
ployerName1=?,JobTitle1=?,JobDescription1
=?,From1=?,To1=?,EmployerName2=?,JobTitle
2=?,JobDescription2=?,From2=?,To2=?,Emplo
yerName3=?,JobTitle3=?,JobDescription3=?,
From3=?,To3=?,platforms=?,programming=?,d
atabaseSkills=?,other=?,Activities=?,Achi
evements=?,Languages=?,Name1=?,Title1=?,C
ompanyName1=?,Address1=?,Phone1=?,Name2=?
,Title2=?,CompanyName2=?,Address2=?,Phone
2=?,Name3=?,Title3=?,CompanyName3=?,Addre
ss3=?,Phone3=? WHERE Ssn="+userId;

PreparedStatement
pstmt=con.prepareStatement(st);

pstmt.setString(1,r.getStreetAddress());
pstmt.setString(2,r.getCity());
pstmt.setString(3,r.getState());
pstmt.setString(4,r.getZip());
pstmt.setString(5,r.getCountry());
pstmt.setString(6,r.getEmail());
pstmt.setString(7,r.getPhone());
pstmt.setString(8,r.getFax());
pstmt.setString(9,r.getObjective());
pstmt.setString(10,r.getSchool1());
pstmt.setString(11,r.getCity1());
pstmt.setString(12,r.getState1() );
pstmt.setString(13,r.getGraduationYear1()
);
pstmt.setString(14,r.getMajor1() );
pstmt.setString(15,r.getGpa1() );
pstmt.setString(16,r.getSchool2());
pstmt.setString(17,r.getCity2() );
pstmt.setString(18,r.getState2() );
pstmt.setString(19,r.getGraduationYear2()
);
pstmt.setString(20,r.getMajor2() );
pstmt.setString(21,r.getGpa2() );

pstmt.setString(22,r.getEmployerName1()
);
pstmt.setString(23,r.getJobTitle1() );
pstmt.setString(24,r.getJobDescription1()
);
pstmt.setString(25,r.getFrom1() );
pstmt.setString(26,r.getTo1() );
pstmt.setString(27,r.getEmployerName2()
);
pstmt.setString(28,r.getJobTitle2() );
pstmt.setString(29,r.getJobDescription2()
);
pstmt.setString(30,r.getFrom2() );
pstmt.setString(31,r.getTo2() );
pstmt.setString(32,r.getEmployerName3()
);
pstmt.setString(33,r.getJobTitle3() );
pstmt.setString(34,r.getJobDescription3()
);
pstmt.setString(35,r.getFrom3() );
pstmt.setString(36,r.getTo3() );
pstmt.setString(37,r.getPlatforms() );
pstmt.setString(38,r.getProgramming() );
pstmt.setString(39,r.getDatabaseSkills()
);
pstmt.setString(40,r.getOther() );
pstmt.setString(41,r.getActivities() );
pstmt.setString(42,r.getAchievements() );
pstmt.setString(43,r.getLanguages() );
pstmt.setString(44,r.getName1() );
pstmt.setString(45,r.getTitle1() );
pstmt.setString(46,r.getCompanyName1() );
pstmt.setString(47,r.getAddress1() );
pstmt.setString(48,r.getPhone1() );

pstmt.setString(49,r.getName2() );
pstmt.setString(50,r.getTitle2() );
pstmt.setString(51,r.getCompanyName2() );
pstmt.setString(52,r.getAddress2() );
pstmt.setString(53,r.getPhone2() );

pstmt.setString(54,r.getName3() );
pstmt.setString(55,r.getTitle3() );
pstmt.setString(56,r.getCompanyName3() );
pstmt.setString(57,r.getAddress3() );
pstmt.setString(58,r.getPhone3() );

ResultSet rs=pstmt.executeQuery();

pstmt.close();
pstmt=null;
}finally {

if(con!=null) {
con.close();
}
}
%>
<jsp:forward page="Welcome1.jsp"/>

 
Pat Wallwork
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This statement is wrong:
ResultSet rs=pstmt.executeQuery();
You first need to do this:
pstmt.executeUpdate();
Then you can query the database again and load it into a ResultSet.
That is one big table by the way. Also, did you declare all fields in your database to be either varchar or char? If not, your code will not work as the values will be incompatible.
Pat
 
vikram nalagampalli
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mr pat,
i tried using executeUpdate and it messed my Database. My database started giving me some SQL dump error and that made me re-do the whole table again.
By the way i am using only varchar. But i am wondering if i can use prepare statements for Updatequeries.
CAn anyone answer me PLSSSSSSSSSSSSSSSSSSSSSSSSSsss
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!