I am a programmer, new to jsp, trying to write some code.
i have written like
<%
int i=1;
String connectionURL = "jdbc:mysql://localhost:3306/registration";
Connection connection = null;
Statement stmt = null;
ResultSet rset = null;
Statement stmt1 = null;
ResultSet rset1 = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
int updateQuery = 0;
try {
connection = DBUtil.createConnection();//DriverManager.getConnection(connectionURL, "root", "root");
String queryString = "select * from course";
System.out.println("select all from course table");
stmt = connection.createStatement();
System.out.println("Statment object "+ stmt );
rset = stmt.executeQuery(queryString);
System.out.println("Result set " + rset );
while (rset.next()) {
System.out.println(" Results...");
String s1 = rset.getString(1);
Double amount = rset.getDouble("amount");
String loginid = rset.getString("loginid");
String queryString1 = "select * from users where loginid = '"+ loginid +"'";
System.out.println("select user details from users table");
System.out.println(queryString1);
stmt1 = connection.createStatement();
System.out.println("Statment object "+ stmt1 );
rset1 = stmt1.executeQuery(queryString1);
System.out.println("Result set " + rset1 );
System.out.println(" name -> " + rset1.getString(2));
%>
<tr class="subtext1">
<td align="left"><%=i%> </td>
<td align="left"><%=rset.getString("name")%></td>
<td align="left"><%=rset.getString("loginid")%></td>
<td align="left"><%=rset.getString("name")%></td>
<td align="left"><%=rset.getString("email")%></td>
<td align="left"><%=rset.getString("iimbtrack")%></td>
<td align="left"><%=rset.getString("result")%></td>
<td align="left">CourseFee/<%=rset.getString("product")%></td>
<td align="left"><%=amount%></td>
<td align="left"><%=rset.getString("fdate")%></td>
</tr>
When I try to print this, it gives error. But when I remove this line:
System.out.println(" name -> " + rset1.getString(2));
It works. Where am I going wrong?
This is the error I get
statment object com.mysql.jdbc.Statement@429be9
Result set com.mysql.jdbc.ResultSet@10a0d51
java.sql.SQLException: Before start of result set
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
at com.mysql.jdbc.ResultSet.checkRowPos(ResultSet.java:703)
at com.mysql.jdbc.ResultSet.getStringInternal(ResultSet.java:5653)
at com.mysql.jdbc.ResultSet.getString(ResultSet.java:5597)
at org.apache.jsp.WEB_002dINF.jsp.secure.transaction.feesreports_jsp._jspService(feesreports_jsp.java:235)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:679)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:461)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:399)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:301)
at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1056)
at org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:261)
at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:388)
at org.apache.struts.tiles.TilesRequestProcessor.processForwardConfig(TilesRequestProcessor.java:316)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:231)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1158)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:397)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:627)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:875)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)