Java SQL ResultSet Exception - java

I'm Developing a Web Application using JSF & PrimeFaces. I have two classes Inputs & DBConn. And i'm executing a SQL command like this
SQL="SELECT COUNT(*) FROM TXN_HEADER WHERE REQUEST_DATE='01-AUG-2014'"
And then in the DBConn class i call the next() method on the ResultSet object inside a while loop condition to print the result.
This works fine and gives me an output.
But when i try to call that ResultSet object to get an output using the same scenario above (using that while loop inside the Inputs class) it gives me the following exception.
java.sql.SQLException: Result set after last row
at oracle.jdbc.driver.GeneratedScrollableResultSet.getString(GeneratedScrollableResultSet.java:879)
at Inputs.commandButton(Inputs.java:41)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.el.parser.AstValue.invoke(AstValue.java:245)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:277)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:526)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:655)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
Then i assumed that after the first use of the next() method the cursor is still in the end though i used the next() method again in that Inputs class.
So i tried using the .beforeFirst() method before going to the 2nd while loop to reset the cursor back to the top. But it gave me the same error again.
Then i tried commenting the 1st while loop i access in the DBConn class so the cursor is at the top for sure. But then it gives me the following error.
java.sql.SQLException: ResultSet.next was not called
at oracle.jdbc.driver.GeneratedScrollableResultSet.getString(GeneratedScrollableResultSet.java:874)
at Inputs.commandButton(Inputs.java:41)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.el.parser.AstValue.invoke(AstValue.java:245)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:277)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:526)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:655)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
How do i resolve this? This is my first time developing a Database Application.
And sorry about these bunch of sys.prints, I used them for debugging.
These are the two classes related to this case:
Inputs Class
import java.sql.SQLException;
import javax.annotation.ManagedBean;
#ManagedBean
public class Inputs {
private String date;
private String showRes;
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getShowRes() {
return showRes;
}
public void setShowRes(String showRes) {
this.showRes=showRes;
}
public void commandButton(){
DBConn nCon=new DBConn();
Calculations nCalc=new Calculations();
nCalc.setPieChartSQL(getDate());
nCon.setSQL(nCalc.getPieChartSQL());
System.out.println("............");
System.out.println(nCon.getResultSet());
System.out.println("............");
System.out.println(nCon.getResultSet());
System.out.println("............");
try {
System.out.println(nCon.getResultSet().getString(1));
//nCon.getResultSet().beforeFirst();
while(nCon.getResultSet().next()){
System.out.println("++++++++++++");
System.out.println(nCon.getResultSet().getString(1));
System.out.println("++++++++++++");
setShowRes(nCon.getResultSet().getString(1));
}
} catch (SQLException e) {
e.printStackTrace();
}
System.out.println("777777777777777777777");
}
}
DBConn Class
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import oracle.jdbc.OracleConnection;
import oracle.jdbc.pool.OracleDataSource;
public class DBConn {
private String sql;
private ResultSet rs;
public ResultSet getResultSet(){
try {
OracleDataSource dataSource=new OracleDataSource();
dataSource.setURL("jdbc:oracle:thin:#172.16.20.45:1521:ABS");
dataSource.setUser("<user>");
dataSource.setPassword("<pass>");
OracleConnection con = (OracleConnection)dataSource.getConnection();
con.setAutoCommit(false);
Statement stmnt = con.createStatement();
rs = stmnt.executeQuery(sql);
System.out.println("-----------");
System.out.println(rs);
System.out.println("-----------");
System.out.println(rs);
System.out.println("-----------");
while(rs.next()){
System.out.println("*************");
System.out.println(rs.getString(1));
System.out.println("*************");
}
} catch (SQLException e) {
e.printStackTrace();
}
return rs;
}
public void setSQL(String sql) {
this.sql=sql;
}
}

I think the problem is in the way you get the resultset. Each time you call nCon.getResultSet() it returns a new resultset. That means you call next method of one resultset object and calls getString(1) in another. Here is my solution.
public void commandButton(){
DBConn nCon=new DBConn();
Calculations nCalc=new Calculations();
nCalc.setPieChartSQL(getDate());
nCon.setSQL(nCalc.getPieChartSQL());
System.out.println("............");
System.out.println(nCon.getResultSet());
System.out.println("............");
System.out.println(nCon.getResultSet());
System.out.println("............");
try {
ResultSet rst=nCon.getResultSet();
rst.beforeFirst();
while(rst.next()){
System.out.println("++++++++++++");
String str=rst.getString(1);
System.out.println("++++++++++++");
setShowRes(str);
}
} catch (SQLException e) {
e.printStackTrace();
}
System.out.println("777777777777777777777");
}

Your getResultMethod() is putting cursor at the end of the ResultSet. And this Exception occurs because you are not calling next() and trying to access the ResultSet in your below method
public void commandButton(){
DBConn nCon=new DBConn();
Calculations nCalc=new Calculations();
nCalc.setPieChartSQL(getDate());
nCon.setSQL(nCalc.getPieChartSQL());
System.out.println("............");
System.out.println(nCon.getResultSet());
System.out.println("............");
System.out.println(nCon.getResultSet());
System.out.println("............");
try {
System.out.println(nCon.getResultSet().getString(1)); //here rs.next() should be called first
//nCon.getResultSet().beforeFirst();
while(nCon.getResultSet().next()){
System.out.println("++++++++++++");
System.out.println(nCon.getResultSet().getString(1));
System.out.println("++++++++++++");
setShowRes(nCon.getResultSet().getString(1));
}
} catch (SQLException e) {
e.printStackTrace();
}
System.out.println("777777777777777777777");
}
Solution
try{
while(rs.next()){
System.out.println(nCon.getResultSet().getString(1));
}
......
}

Related

connection java.sql.SQLNonTransientConnectionException: Could not create connection to database server

I am trying to add some bunch of records in MySQL database usign jdbc in java. This program works absolutely fine for 100 records. But after 100 records i get following error.
Exception occured while obtaining
connectionjava.sql.SQLNonTransientConnectionException: Could not create connection to database server.
java.lang.NullPointerException
at com.rest.EmployeeRest.insertDesigMySQLData(EmployeeRest.java:446)
at com.rest.EmployeeRest.syncDesignation(EmployeeRest.java:188)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:205)
at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1542)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1473)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409)
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:558)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:733)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:442)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1082)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:623)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
After google about this error, someone tell to use telnet command on localhost 3306(MySQL port). and it gives me "Too many connections" error.
Can anyone help me to solve this issue.
API code to get Data and add to MySQL:
ArrayList<Employee> arrDesig = getAllDesig();
setTotRecords(arrDesig.size());
System.out.println("Oracle TotRecords = "+getTotRecords());
if(arrDesig.size() > 0){
for(int iCnt=0; iCnt<arrDesig.size(); iCnt++){
if(insertDesigMySQLData(arrDesig.get(iCnt)) == 1){
mysqlDat++;
}
System.out.println("MySQL inserted data = "+mysqlDat);
}
if(getTotRecords() == mysqlDat){
retval = 1;
}else{
retval = 0;
}
}else{
retval = 0;
}
MySQL code to add:
int retval = 0;
OracleDataSource objMySQLDataSource = new OracleDataSource("mysql");
try{
Connection connection = objMySQLDataSource.getDbConnection();
CallableStatement pstmt=connection.prepareCall("{call addDesig(?,?,?)}");
pstmt.setString(1,objEmployee.getDesig_id());
System.out.println("getDesig_id() = "+objEmployee.getDesig_id());
pstmt.setString(2,objEmployee.getDesig_nm());
System.out.println("getDesig_nm() = "+objEmployee.getDesig_nm());
pstmt.registerOutParameter(3, Types.NUMERIC);
pstmt.executeUpdate();
retval = pstmt.getInt(3);
pstmt.close();
}catch (Exception e) {
retval = 0;
e.printStackTrace();
}finally{
objMySQLDataSource.connectionClose();
}
return retval;
Oracle Connection
OracleDataSource(){
setUrl("jdbc:oracle:thin:#dburl");
setDriver("oracle.jdbc.OracleDriver");
setUserName("admin");
setPassword("**********");
}
MySQL Connection
OracleDataSource(String mysql){
setUrl("jdbc:mysql://localhost:3306/academicdb?verifyServerCertificate=false&useSSL=true&useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC");
setDriver("com.mysql.cj.jdbc.Driver");//com.mysql.jdbc.Driver
setUserName("root");
setPassword("");
}
public Connection getDbConnection() {
Connection con = null;
try{
Class.forName(getDriver());
con = DriverManager.getConnection(getUrl(), getUserName(), getPassword());
} catch (Exception se) {
System.out.println("Exception occured while obtaining connection" + se.toString());
}
return con;
}

Java connecting JDBC to Dynamic Web App

I have run into a problem that I have been trying to figure out for days:
I added my driver: mysql-connector-java-5.1.40.jar to build path.
web-inf lib folder, apache tomcat lib folder. And also I have it in web app libaries.
However when I just run a main class and run it works, it is something to do with the web app?
This is my code:
This is the servlet class, that I use to connect to my database
package sql;
import java.io.IOException;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class RegisterServlet
*/
#WebServlet("/register")
public class RegisterServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private DbUtil sql = new DbUtil();
/**
* #see HttpServlet#HttpServlet()
*/
public RegisterServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* #see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String email = request.getParameter("email");
String username = request.getParameter("username");
String password = request.getParameter("password");
if (sql.addToAccountToDatabase(username, password, email)) {
System.out.println("Gongratz");
} else {
System.out.println("mhhh ?");
}
}
/**
* #see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
}
this is the second class how i make connection
package sql;
import java.sql.*;
public class DbUtil {
public Connection getConnection() {
Connection connect = null;
try {
String url = "jdbc:mysql://hidden:3306/hidden";
connect = DriverManager.getConnection(url, "hidden", "hidden");
return connect;
} catch (Exception e) {
System.out.println("Cannot connect to database");
e.printStackTrace();
}
return connect;
}
public boolean addToAccountToDatabase(String username, String password, String email) {
try {
String query = "INSERT INTO Account (username, password, email) VALUES (?, ?,?)";
PreparedStatement pStat = getConnection().prepareStatement(query);
pStat.setString(1, username);
pStat.setString(2, password);
pStat.setString(3, email);
pStat.executeUpdate();
return true;
} catch (Exception e) {
System.out.println("User already exists");
e.printStackTrace();
return false;
}
}
}
And I get this error:
Cannot connect to database
java.sql.SQLException: No suitable driver found for jdbc:mysql://192.185.227.214:3306/ratekas9_illegalminds
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at sql.DbUtil.getConnection(DbUtil.java:15)
at sql.DbUtil.addToAccountToDatabase(DbUtil.java:34)
at sql.RegisterServlet.doPost(RegisterServlet.java:40)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:108)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:784)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:802)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
User already exists
java.lang.NullPointerException
at sql.DbUtil.addToAccountToDatabase(DbUtil.java:34)
at sql.RegisterServlet.doPost(RegisterServlet.java:40)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:108)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:784)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:802)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
mhhh ?
Because the String "jdbc:mysql" doesn't declare the driver Class itself, but only the name registered by a potential driver. You have to force the JVM to load the Driver class with a :
Class.forName("com.mysql.jdbc.Driver").newInstance();
before starting the JDBC connection.
You need 3 steps to solve your problem:
Add this code before connection Class.forName("com.mysql.jdbc.Driver");
Add 'JConnector.jar' into your project and build path.
Don't try enter same person because there is error in stack trace "User all ready exist ".
Adding the JAR file into your CLASSPATH (for compilation needs) / project's BUILDPATH and also under your project's WEB-INF/lib folder (for runtime references, i.e., when you deploy your application to an application server). For further reference, please go through this link
Class.forName("com.mysql.jdbc.Driver");
This is no longer required as per Official Java documentation here, but it is a mandatory step if you are using prior versions of JDBC 4.0.
This question can provide you lot many details on this regards.
Hope all these details help you resolve your issue!

DELETE triggers SQLITE_ERROR SQL error or missing database (Connection is closed)

I don't understand why I am getting this error.. In my web application I have used many methods where I execute insert, select, update etc where all of them works correctly without errors... Now I want to implement a delete action. So, I have:
public void deleteBox(Label label)
throws SQLException, ClassNotFoundException {
System.out.println("Deleting box from BOXES");
sq = "DELETE FROM BOXES WHERE product=? AND version=? AND productionD=? AND AA=?";
try {
Class.forName(typeDB);
c = DriverManager.getConnection(path);
PreparedStatement stm = c.prepareStatement(sq);
stm.setString(1, label.getProduct());
stm.setString(2, label.getVersion());
stm.setString(3, label.getDateProduction());
stm.setString(4, label.getPacketNumber());
stm.executeUpdate();
} catch (SQLException e) {
System.out.println("hereeee error: " + e.getMessage());
e.printStackTrace();
} finally {
if (stm != null)
stm.close(); //<---
if (c != null)
c.close();
}
}
where path and typeDB are defined as:
private final String path = "jdbc:sqlite:C:\\DB_LABELS\\labels.sqlite";
private final String typeDB= "org.sqlite.JDBC";
and in the start of the class:
private Connection c = null;
PreparedStatement stm = null;
This method is called from the servlet here:
try{
Label box = (Label) session.getAttribute("boxFound");
action.deleteBox(box); //here I call the method
//some other stuff here..
action.addTransaction(box, "extract", timeStamp1, user.getId());
old = action.searchQuantityOfPackage(box);
}catch(SQLException | ClassNotFoundException e){
System.err.println("Exception at extract. More: " + e);
}
When it is executed I get an error:
Deleting box from BOXES
Exception at extract. More: java.sql.SQLException: [SQLITE_ERROR] SQL error or missing database (Connection is closed)
and all the other commands aren't executed inside the try. I don't understand why is this happening. As I said in the begging I use the same setting for other sql actions so both path and typeDB must be defined correctly. If I delete action.deleteBox(box); no error is happening, so sth is happening in this method...
ALSO
I forgot to mention that the delete of the row in the table BOXES is happening despite the error!
I add also the ful stack trace
Exception at extract. More: java.sql.SQLException: [SQLITE_ERROR] SQL error or missing database (Connection is closed)
java.sql.SQLException: [SQLITE_ERROR] SQL error or missing database (Connection is closed)
at org.sqlite.core.DB.newSQLException(DB.java:890)
at org.sqlite.core.CoreStatement.internalClose(CoreStatement.java:109)
at org.sqlite.jdbc3.JDBC3Statement.close(JDBC3Statement.java:35)
at gr.products.labelInventory.ActionsDB.deleteBox(ActionsDB.java:557)
at gr.products.labelInventory.Inventory.processRequest(Inventory.java:285)
at gr.products.labelInventory.Inventory.doGet(Inventory.java:652)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at gr.products.labelInventory.LogFilter.doFilter(LogFilter.java:22)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:537)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1085)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1556)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1513)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:724)
this line at gr.products.labelInventory.ActionsDB.deleteBox(ActionsDB.java:557) points to the <-- i put in the code.

mySql Column not found error occuring from servlet

I query a database to obtain all values from it.The query sometimes executes perfectly but at other times the query fails like this:
select * from myTable where objtype='EQUI' and scnrtype='C'
java.sql.SQLException: Column 'dataType' not found.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1084)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:973)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:918)
at com.mysql.jdbc.ResultSetImpl.findColumn(ResultSetImpl.java:1162)
at com.mysql.jdbc.ResultSetImpl.getCharacterStream(ResultSetImpl.java:2056)
at com.hastha.marerp.googlemaps.DBUtils.getScreenFields(DBUtils.java:672)
at com.hastha.marerp.googlemaps.DBUtils.getScreenFieldsJSON(DBUtils.java:754)
at com.hastha.marerp.googlemaps.DynamicMenuItemBuilder.doGet(DynamicMenuItemBuilder.java:67)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEondpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
The column dataType has char(8) as it's data type.
I have tried both rs.getString() and rs.getCharecterStream() where rs is the ResultSet obtained from this query.I think this has no effect on the problem because the error occurs before this line is even reached.
This is a description of myTable
This is my code:
public ArrayList<ScenarioFieldInfo> getScreenFields(String objType, String scenarioType)
{
System.out.println("Input args objType: "+objType+" and scenarioType: "+scenarioType);
PreparedStatement pst = null;
ResultSet rs = null;
ArrayList<ScenarioFieldInfo> scenarioFieldList = new ArrayList<ScenarioFieldInfo>();
try {
String sql = "select * from myTable where objtype='"+objType+"' and scnrtype='"+scenarioType+"'";
System.out.println(sql);
pst = (PreparedStatement) conn.prepareStatement(sql.toString());
rs = pst.executeQuery();
while(rs.next()){
ScenarioFieldInfo fieldInfo = new ScenarioFieldInfo();
fieldInfo.fieldName = rs.getString("fieldName");
fieldInfo.fieldLabel = rs.getString("FieldLabel");
//fieldInfo.sapType=rs.getString("dataType");
BufferedReader reader=new BufferedReader(rs.getCharacterStream("dataType"));
try {
String sapType=reader.readLine();
fieldInfo.sapType=sapType;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
fieldInfo.parameter=rs.getString("PARAMETER");
scenarioFieldList.add(fieldInfo);
}
System.out.println("There are "+scenarioFieldList.size()+" screen fields");
} catch (SQLException e) {
e.printStackTrace();
}
finally
{
close(rs);
close(pst);
}
return scenarioFieldList;
}
I found that the code was crashing because I had getCharecterStream instead of getString which was causing an error in my case.Modiying the code to:
rs.getString("dataType");
fixed the issue

Column position '0' is out of range. The number of columns for this ResultSet is '3'

In a previous piece of code I received the exact same error I listed in the title.
I had a username validator in my code but forgot to include the following code:
password =ESAPI.validator().getValidInput("Login password", password, "Password", 20, false);
After adding that I resolved the issue.
Now in my next java page I have run into the same problem and reviewed the code and have not been able to find what I am missing, if I am in fact missing something.
I had this same error with another piece of code I was working on and was able to resolve it as I had forgot to include another line of code.
For this piece of code however I have gone over it several times and cannot figure what is wrong with it.
Here is the code:
package com.tunestore.action;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.action.DynaActionForm;
import org.apache.struts.util.MessageResources;
import org.owasp.esapi.ESAPI;
import com.tunestore.util.IWithDataSource;
public class RegisterAction extends Action implements IWithDataSource {
private DataSource dataSource;
public void setDataSource(DataSource dataSource) {
this.dataSource = dataSource;
}
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
DynaActionForm daf = (DynaActionForm)form;
ActionMessages errors = new ActionMessages();
ActionForward forward = mapping.getInputForward();
MessageResources resources = getResources(request);
//ESAPI START
if (!ESAPI.validator().isValidInput("Register username", daf.getString("username"), "SafeString", 20, false)) {
//ESAPI END
errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("errors.required", resources.getMessage("prompt.username")));
}
//ESAPI START
if (!ESAPI.validator().isValidInput("Register password", daf.getString("password"), "password", 20, false)) {
//ESAPI END
errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("errors.required", resources.getMessage("prompt.password")));
}
//ESAPI START
if (!ESAPI.validator().isValidInput("Register confirm password", daf.getString("rptpass"), "password", 20, false)) {
//ESAPI END
errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("errors.required", resources.getMessage("prompt.rpt")));
}
if ((null != daf.getString("password")) && (null != daf.getString("rptpass"))) {
if (! daf.getString("password").equals(daf.getString("rptpass"))) {
errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.rptpass.nomatch"));
}
}
Connection conn = null;
try {
conn = dataSource.getConnection();
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT COUNT(*) USERCNT "
+ "FROM TUNEUSER "
+ "WHERE USERNAME = '"
+ daf.getString("username")
+ "'");
rs.next();
if (rs.getInt("USERCNT") > 0) {
errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.user.exists"));
} else if (errors.isEmpty()) {
//ESAPI START
String sql = "INSERT INTO TUNEUSER (USERNAME,PASSWORD,BALANCE) VALUES (?, ?, ?)";
PreparedStatement pStmt = conn.prepareStatement(sql);
pStmt.setString(0, daf.getString("username"));
pStmt.setString(1, daf.getString("password"));
pStmt.setDouble(2, 0.00);
pStmt.executeUpdate();
//ESAPI END
ActionMessages msgs = getMessages(request);
msgs.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("user.added"));
forward = mapping.findForward("success");
}
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
if (conn != null) {
try { conn.close(); } catch (Exception e) {}
}
}
request.setAttribute("ERRORS.REGISTER", errors);
return forward;
}
}
The code is for a registration form. When someone tries to register though the following error is given in return.
java.sql.SQLException: The column position '0' is out of range. The number of columns for this ResultSet is '3'.
at org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unknown Source)
at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
at org.apache.derby.client.am.ColumnMetaData.getColumnType(Unknown Source)
at org.apache.derby.client.am.PreparedStatement.setString(Unknown Source)
at org.apache.commons.dbcp.DelegatingPreparedStatement.setString(DelegatingPreparedStatement.java:132)
at com.tunestore.action.RegisterAction.execute(RegisterAction.java:90)
at org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:110)
at org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
at org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:306)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at com.tunestore.servlet.PersistenceFilter.doFilter(PersistenceFilter.java:77)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:244)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:108)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:558)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:379)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:259)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:281)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: org.apache.derby.client.am.SqlException: The column position '0' is out of range. The number of columns for this ResultSet is '3'.
at org.apache.derby.client.am.ColumnMetaData.checkForValidColumnIndex(Unknown Source)
... 34 more
ROOT CAUSE
org.apache.derby.client.am.SqlException: The column position '0' is out of range. The number of columns for this ResultSet is '3'.
at org.apache.derby.client.am.ColumnMetaData.checkForValidColumnIndex(Unknown Source)
at org.apache.derby.client.am.ColumnMetaData.getColumnType(Unknown Source)
at org.apache.derby.client.am.PreparedStatement.setString(Unknown Source)
at org.apache.commons.dbcp.DelegatingPreparedStatement.setString(DelegatingPreparedStatement.java:132)
at com.tunestore.action.RegisterAction.execute(RegisterAction.java:90)
at org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:110)
at org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
at org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:306)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at com.tunestore.servlet.PersistenceFilter.doFilter(PersistenceFilter.java:77)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:244)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:108)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:558)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:379)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:259)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:281)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
The error appears to be pointing to line 90 of my code which is:
pStmt.setString(0, daf.getString("username"));
Yet this line of code looks correct to me. What could I be missing?
Column indexes start at 1 in JDBC
I can't see you calling setString in the code, but the stack trace clearly says execute is calling setString at line #90. Is the code you posted exactly what's running when you get this exception?

Categories