I'm trying to get JDO working within a Servlet; just a simple, basic Servlet. I know that a Servlet can connect to my db because a non-JDO servlet does it fine, and prints out data from the db (the following is at the start of a simple Servlet):
StringBuilder sb = new StringBuilder();
Connection conn = null;
try {
String userName = "jdo";
String password = "jdo";
String url = "jdbc:mysql://192.168.2.203:3306/jdo";
Class.forName( "com.mysql.jdbc.Driver" ).newInstance();
conn = DriverManager.getConnection( url, userName, password );
sb.append( "Database connection established" );
Statement s = conn.createStatement();
s.executeQuery( "select id, make, model from car limit 1" );
ResultSet rs = s.getResultSet();
while ( rs.next() ) {
int id = rs.getInt( "id" );
String make = rs.getString( "make" );
String model = rs.getString( "model" );
sb.append( "id = " + id + ", make = " + make + ", model = " + model + "\n" );
}
rs.close();
s.close();
}
That's all fine, the StringBuilder gets the data from the db appended no problem. What doesn't work, however, is the following. It throws a stack trace at the last line (line 28) I'm about to paste in here (this code is also at the start of a simple Servlet, just a different Servlet to the one that contained the previous code):
Properties p = new Properties();
p.setProperty( "javax.jdo.option.ConnectionDriverName", "com.mysql.jdbc.Driver" );
p.setProperty( "javax.jdo.option.ConnectionURL", "jdbc:mysql://192.168.2.203:3306/jdo" );
p.setProperty( "javax.jdo.option.ConnectionUserName", "jdo" );
p.setProperty( "javax.jdo.option.ConnectionPassword", "jdo" );
PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory( p ); // this is line 28
The stack trace is at the bottom of this post, as it's rather long.
These two Servlets exist in the same war file, within which is the MySQL Connector/J jar file:
mkns#squeeze:~/workspace/JdoServlet$ jar tf dist/jdoservlet.war | grep mysql
WEB-INF/lib/mysql-connector-java-5.1.6.jar
I'm baffled as to why the DataNucleus libs are not finding the MySQL Connector/J driver jar file? I may be missing the obvious here, but I've stripped my Servlets back as much as I can to see where the problem is (as above) and I can't figure out where I'm going wrong. Can anyone point out the mistake I'm making?
I'm using the latest version of DataNucleus, 3.0.9.
--- 8< ---
And now the stack trace; this is the full stack trace taken from the Tomcat6 catalina log file. Note that the lines from my app are in the masked out package name of com.xxxxxxxxxx.jdoservlet.*, so if you look for that, you can identify where the exception was thrown by my app.
12-Apr-2012 18:48:47 org.datanucleus.store.rdbms.RDBMSStoreManager <init>
SEVERE: Failed initialising database.
No suitable driver found for jdbc:mysql://192.168.2.203:3306/jdo
org.datanucleus.exceptions.NucleusDataStoreException: No suitable driver found for jdbc:mysql://192.168.2.203:3306/jdo
at org.datanucleus.store.rdbms.ConnectionFactoryImpl$ManagedConnectionImpl.getConnection(ConnectionFactoryImpl.java:459)
at org.datanucleus.store.rdbms.RDBMSStoreManager.<init>(RDBMSStoreManager.java:264)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.datanucleus.plugin.NonManagedPluginRegistry.createExecutableExtension(NonManagedPluginRegistry.java:681)
at org.datanucleus.plugin.PluginManager.createExecutableExtension(PluginManager.java:290)
at org.datanucleus.NucleusContext.createStoreManagerForProperties(NucleusContext.java:468)
at org.datanucleus.NucleusContext.initialise(NucleusContext.java:280)
at org.datanucleus.api.jdo.JDOPersistenceManagerFactory.freezeConfiguration(JDOPersistenceManagerFactory.java:591)
at org.datanucleus.api.jdo.JDOPersistenceManagerFactory.createPersistenceManagerFactory(JDOPersistenceManagerFactory.java:326)
at org.datanucleus.api.jdo.JDOPersistenceManagerFactory.getPersistenceManagerFactory(JDOPersistenceManagerFactory.java:195)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at javax.jdo.JDOHelper$16.run(JDOHelper.java:1956)
at java.security.AccessController.doPrivileged(Native Method)
at javax.jdo.JDOHelper.invoke(JDOHelper.java:1951)
at javax.jdo.JDOHelper.invokeGetPersistenceManagerFactoryOnImplementation(JDOHelper.java:1159)
at javax.jdo.JDOHelper.getPersistenceManagerFactory(JDOHelper.java:839)
at javax.jdo.JDOHelper.getPersistenceManagerFactory(JDOHelper.java:698)
at com.xxxxxxxxxx.jdoservlet.Test.process(Test.java:28)
at com.xxxxxxxxxx.jdoservlet.AbstractServlet.doPost(AbstractServlet.java:35)
at com.xxxxxxxxxx.jdoservlet.AbstractServlet.doGet(AbstractServlet.java:27)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.sql.SQLException: No suitable driver found for jdbc:mysql://192.168.2.203:3306/jdo
at java.sql.DriverManager.getConnection(DriverManager.java:602)
at java.sql.DriverManager.getConnection(DriverManager.java:154)
at org.apache.commons.dbcp.DriverManagerConnectionFactory.createConnection(DriverManagerConnectionFactory.java:78)
at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582)
at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:1148)
at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:106)
at org.datanucleus.store.rdbms.ConnectionFactoryImpl$ManagedConnectionImpl.getConnection(ConnectionFactoryImpl.java:444)
... 39 more
Nested Throwables StackTrace:
java.sql.SQLException: No suitable driver found for jdbc:mysql://192.168.2.203:3306/jdo
at java.sql.DriverManager.getConnection(DriverManager.java:602)
at java.sql.DriverManager.getConnection(DriverManager.java:154)
at org.apache.commons.dbcp.DriverManagerConnectionFactory.createConnection(DriverManagerConnectionFactory.java:78)
at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582)
at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:1148)
at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:106)
at org.datanucleus.store.rdbms.ConnectionFactoryImpl$ManagedConnectionImpl.getConnection(ConnectionFactoryImpl.java:444)
at org.datanucleus.store.rdbms.RDBMSStoreManager.<init>(RDBMSStoreManager.java:264)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.datanucleus.plugin.NonManagedPluginRegistry.createExecutableExtension(NonManagedPluginRegistry.java:681)
at org.datanucleus.plugin.PluginManager.createExecutableExtension(PluginManager.java:290)
at org.datanucleus.NucleusContext.createStoreManagerForProperties(NucleusContext.java:468)
at org.datanucleus.NucleusContext.initialise(NucleusContext.java:280)
at org.datanucleus.api.jdo.JDOPersistenceManagerFactory.freezeConfiguration(JDOPersistenceManagerFactory.java:591)
at org.datanucleus.api.jdo.JDOPersistenceManagerFactory.createPersistenceManagerFactory(JDOPersistenceManagerFactory.java:326)
at org.datanucleus.api.jdo.JDOPersistenceManagerFactory.getPersistenceManagerFactory(JDOPersistenceManagerFactory.java:195)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at javax.jdo.JDOHelper$16.run(JDOHelper.java:1956)
at java.security.AccessController.doPrivileged(Native Method)
at javax.jdo.JDOHelper.invoke(JDOHelper.java:1951)
at javax.jdo.JDOHelper.invokeGetPersistenceManagerFactoryOnImplementation(JDOHelper.java:1159)
at javax.jdo.JDOHelper.getPersistenceManagerFactory(JDOHelper.java:839)
at javax.jdo.JDOHelper.getPersistenceManagerFactory(JDOHelper.java:698)
at com.xxxxxxxxxx.jdoservlet.Test.process(Test.java:28)
at com.xxxxxxxxxx.jdoservlet.AbstractServlet.doPost(AbstractServlet.java:35)
at com.xxxxxxxxxx.jdoservlet.AbstractServlet.doGet(AbstractServlet.java:27)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)
I had the exact same error except it was for the postgres jdbc driver on tomcat7 on a machine running ubuntu 12.04. I ended up taking the jdbc driver out of the war file and put it into /usr/share/tomcat7/lib/. This is a folder that tomcat looks for jar files.
This solution may not be for everyone as the jdbc driver will now be accessible to all servlets in all tomcat containers.
First thing: You typically omit the call to newInstance after the Class.forName call to load the database driver.
Second: DataNucleus prefers sometimes its own configuration. Have you tried to set the following properties according to the DataNucleus website?
datanucleus.ConnectionDriverName=com.mysql.jdbc.Driver
datanucleus.ConnectionURL=jdbc:mysql://'host':'port'/'db-name'
datanucleus.ConnectionUserName='user-name'
datanucleus.ConnectionPassword='password'
http://www.datanucleus.org/products/datanucleus/rdbms/support.html
Furthermore check that the driver was successfully deployed.
Does putting the jar in the directory specified in this question help?
Related
This question already has answers here:
Is it safe to use a static java.sql.Connection instance in a multithreaded system?
(2 answers)
Closed 6 years ago.
I did some web app to deploy in production. But after several hours (looks like 8 hour), I can't communicate with DB.
Here is my Connect.java
package util;
import java.sql.Connection;
import java.sql.DriverManager;
import javax.xml.ws.Response;
public class Connect {
public static Connection connection = null;
public static Connection getConnection() {
if (connection != null) {
return connection;
} else {
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost/DBPRK?autoReconnect=true&useUnicode=true&characterEncoding=utf8";
String username = "prk";
String password = "prk";
try {
Class.forName(driver);
connection = DriverManager.getConnection(url, username, password);
} catch (Exception e) {
System.out.println("ERROR");
}
return connection;
}
}
}
and Here is error message that i got from tomcat log:
com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
java.net.SocketException
MESSAGE: Software caused connection abort: socket write error
STACKTRACE:
java.net.SocketException: Software caused connection abort: socket write error
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:113)
at java.net.SocketOutputStream.write(SocketOutputStream.java:159)
at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140)
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2616)
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2547)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1512)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1622)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2370)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2297)
at com.mysql.jdbc.Statement.executeQuery(Statement.java:1183)
at controller.GetAllClients.processRequest(GetAllClients.java:39)
at controller.GetAllClients.doGet(GetAllClients.java:73)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:745)
** END NESTED EXCEPTION **
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2634)
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2547)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1512)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1622)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2370)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2297)
at com.mysql.jdbc.Statement.executeQuery(Statement.java:1183)
at controller.GetAllClients.processRequest(GetAllClients.java:39)
at controller.GetAllClients.doGet(GetAllClients.java:73)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:745)
Btw I use pure jsp with no framework.
Any help is very appreciate.
This problem may occur in following cases:
When we are trying to get too many DB connections.
When a DB connection is idle for a long time.
So, in your program try to close connection after usage, and get a new connection.
Buddy, add port number (3306) in your connection in the String Url
This is showing exception in your code at following line:
at controller.GetAllClients.processRequest(GetAllClients.java:39)
at controller.GetAllClients.doGet(GetAllClients.java:73)
The reason that might be causing this exception is that probably you are not closing connections once obtained and used.
In any computer system, there are a limited number of sockets available for connections and this strongly depends on your hardware specification and driver you are using for connection.
A connection to a database is something that has high cost in terms of resources and performance. This must be taken care every time when you think of connecting to a database.
Now assume a situation, where you have 5 bikes and 7 riders, all riders need a bike, so you can allocate 1 bike to each rider but only upto 5 riders, then what about rest 2 ?. So now only option is to wait for any two riders who complete their ride and return the bike so that you can allocate it to other twos... But in your case, first 5 took away the bike (got connection to database), completed their ride (executed their queries to database) but didn't return bike (are not closing the connection).
Likewise, in your case it is being allotted but not being released after usage, which in turn occupies all available socket and no socket is available to provide connection.
I assume you are catching the "connection" (returned by getConnection() method) in "con" variable.
Now,
con.close();
just only this needs to be written there.
And one more thing, currently all sockets are occupied you need to restart the database server (MySQL etc.) and project server (Tomcat etc.). And add above 1 line code everywhere after database usage is over.
This question already has answers here:
The infamous java.sql.SQLException: No suitable driver found
(21 answers)
Closed 7 years ago.
I have a Java class that accesses a MySQL database through JDBC that I use in a JSP running on Tomcat, and I am getting No Driver Found Exception.
I have a method:
private static Statement makeStatement() {
try{
com.mysql.jdbc.Driver d = null;
try{d = new com.mysql.jdbc.Driver();}catch(Exception e){
System.out.println("ERROR BY NEW DRIVER " + e.toString() +
"\n");e.printStackTrace();}
Connection con = DriverManager.getConnection(url, user, password);
return con.createStatement();
}catch(java.sql.SQLException ex){
System.out.println("ERROR IN makeStatement " + "\nERROR - " +
ex.toString() + "\n ERROR CODE:\n " + ex.getErrorCode() +
"\nSQLSTATE:\n " + ex.getSQLStat e());ex.printStackTrace();}
return null;
}
That throws an error at Connection con = DriverManager.getConnection(url, user, password); Here is my printout from catalina.out:
Received Parameters
ERROR IN makeStatement
ERROR - java.sql.SQLException: No suitable driver found for
ERROR CODE:
0
SQLSTATE:
08001
java.sql.SQLException: No suitable driver found for
at java.sql.DriverManager.getConnection(DriverManager.java:602)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at message.Message.makeStatement(Message.java:72)
at message.Message.query(Message.java:79)
at message.Message.getName(Message.java:225)
at org.apache.jsp.message_jsp._jspService(message_jsp.java:288)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
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:803)
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:174)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:548)
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:874)
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)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Thread.java:619)
ERROR IN QUERY java.lang.NullPointerException
ERROR in getName java.lang.NullPointerException
-----------------------------------
Received Parameters
newMessage =
newpassword =
verifypassword =
sendinfo =
username = Eli
newusername =
login = login
password = tree
ERROR IN makeStatement
ERROR - java.sql.SQLException: No suitable driver found for
ERROR CODE:
0
SQLSTATE:
08001
java.sql.SQLException: No suitable driver found for
at java.sql.DriverManager.getConnection(DriverManager.java:602)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at message.Message.makeStatement(Message.java:72)
at message.Message.query(Message.java:79)
at message.Message.validUser(Message.java:195)
at org.apache.jsp.message_jsp._jspService(message_jsp.java:123)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
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:803)
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:174)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:548)
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:874)
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)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Thread.java:619)
ERROR IN QUERY java.lang.NullPointerException
ERROR in validUser java.lang.NullPointerException
ERROR IN makeStatement
ERROR - java.sql.SQLException: No suitable driver found for
ERROR CODE:
0
SQLSTATE:
08001
java.sql.SQLException: No suitable driver found for
at java.sql.DriverManager.getConnection(DriverManager.java:602)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at message.Message.makeStatement(Message.java:72)
at message.Message.query(Message.java:79)
at message.Message.getName(Message.java:225)
at org.apache.jsp.message_jsp._jspService(message_jsp.java:288)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
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:803)
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:174)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:548)
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:874)
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)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Thread.java:619)
ERROR IN QUERY java.lang.NullPointerException
ERROR in getName java.lang.NullPointerException
The only error that matters is the one in makeStatement() as that failing causes all the other errors. I have quadruple checked that I have the correct jar files in my WEB-INF/lib directory and I have restarted Tomcat more times than I would ever want to. I have a separate webapp that uses makeStatement() in a different .java file, and that webapp runs fine. Even weirder is that I have this in the .java:
static {
System.err.println("\n\nTEST MYSQL ACCESS: dump all relevant tables:");
dump();
System.err.println("END OF MYSQL ACCESS ACCESS.");
}
public static void dump() {
try {
readUsers();
for (UserRecord u: users)
System.err.println(u.username+" "+u.password);
} catch (Exception e) {System.err.println(e);}
}
where readUsers() reads all the users from the database using makeStatement(). This actually works and all the users in the database are printed (not shown here for obvious reasons :) ) and then the driver not found error occurs.
java.sql.SQLException: No suitable driver found
This exception can have 2 causes:
The JDBC driver is not loaded at all.
URL does not match any of the loaded JDBC drivers.
Since the driver seems to be loaded (although in an incorrect manner), it look like that the URL is plain wrong. Ensure that the value of your url variable matches the following format
jdbc:mysql://localhost:3306/dbname
See also:
Connect Java to a MySQL database
Unrelated to the concrete problem: Java code doesn't belong in a JSP file. Work on that as well. Your exception handling is also terrible, you should throw the exception (so that it blocks executing the remnant of the code) instead of printing the message/trace and then continue with the code.
I had to remove mysql-connector-java-*.jar from WEB-INF/lib and add it into tomcat6/lib folder. (tomcat6 is where tomcat was installed.) I do not know why this worked but it worked for me.
Did you register your class with the Driver? For example:
Class.forName("net.sourceforge.jtds.jdbc.Driver");
DriverManager.getConnection(url,user,password);
Are you passing an emtpy url string to getConnection()? The error message starts out
No suitable driver found for ERROR
No suitable driver found for [blank]? Seems like you're not passing a url here.
Go to library folder of your project and right click it,then go to 'Add Library' option.Now add the mysql.jdbc.Driver
In may i've created a Java servlet which allow me to query my hive tables on Cosmos .
Before the migration to cygnus 0.8.2 , my data were pushed to a table named "hostabee" which I can still query from my Java application . But now a table is automatically created for each of the entity pushed to cosmos . At first , i've seen no problem, this even made my project simpler . But I can't query the new tables from my application . Instead i get this error
java.sql.SQLException: Query returned non-zero code: 10, cause: FAILED: Error in semantic analysis: Line 1:15 Table not found 'guillaume_jourdain_hostabee_hives_a_hive_column'
at org.apache.hadoop.hive.jdbc.HiveStatement.executeQuery(HiveStatement.java:194)
at HiveBasicClientServlet.doQuery(HiveBasicClientServlet.java:100)
at HiveBasicClientServlet.demo(HiveBasicClientServlet.java:189)
at HiveBasicClientServlet.doGet(HiveBasicClientServlet.java:44)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:701)
or this one
java.sql.SQLException: Query returned non-zero code: 9, cause: FAILED: Execution Error, return code -101 from shark.execution.SparkTask
at org.apache.hadoop.hive.jdbc.HiveStatement.executeQuery(HiveStatement.java:194)
at HiveBasicClientServlet.doQuery(HiveBasicClientServlet.java:100)
at HiveBasicClientServlet.demo(HiveBasicClientServlet.java:189)
at HiveBasicClientServlet.doGet(HiveBasicClientServlet.java:44)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:701)
The table "guillaume_jourdain_hostabee_hives_a_hive_column" exist and i can query it from hive with a ssh connection . Do you have an idea from where my problem come from ? I can show you part of my code if necessary .
The following error:
Error in semantic analysis: Line 1:15 Table not found 'guillaume_jourdain_hostabee_hives_a_hive_column'
Is not due to Cygnus 0.8.2 but to a rare behaviour we have experienced with our Global Instance of Cosmos at FIWARE Lab. Fortunately, it is easily fixed by prefixing the default database name (which is default :)) to the table name. I.e. if you had somethind like:
select * from mytable;
Now you have to write:
select * from default.mytable;
ok I have really a strange problem that I keep looking for solution in google and yahoo for almost 4 hours today. And I desperately looking for a solution.
public static String [] checkCardAccount(String cardNumber, String cardIssuer, String securityNumber){
URL url = null;
try {
url = new URL("http://localhost:8999/bankcard?wsdl");
} catch (MalformedURLException e) {
e.printStackTrace();
}
QName qname = new QName("http://server.bcard.soap.com/","BankCardImplService");
Service service = Service.create(url,qname);
BankCard bankcard = service.getPort(BankCard.class);
return bankcard.getCardClientData(cardNumber, cardIssuer);
}
the above code is my client for accessing the SOAP service, it really works in a standalone java application but when I embed it to my Java Struts application it says the following error below
javax.xml.ws.WebServiceException: Undefined port type:
{http://bankcard.api.com/}BankCard at
com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:349)
at
com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:355)
at javax.xml.ws.Service.getPort(Service.java:161) at
com.api.bankcard.BankCardClient.checkCardAccount(BankCardClient.java:25)
at com.action.CardregAction.execute(CardregAction.java:18) 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:191)
at
org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:305)
at
org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
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:637) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)
Now I really see that the problem is the target namespace because as I change it the error changes to that it says that the valid services is {http://bankcard.api.com/}BankCard
where I went wrong? this code works on standalone on Java Application but not in my Java Struts web app
give endpointIneterface in #WebService annotation in the implementation class, if you dont give endpoint interface, you have to mention fully qualified port name while using getPort method.
service.getPort("PortQName",BankCard.class);
You need to annotate the BankCardImpl class with #WebService(name="BankCard")
You can then use service.getPort(BankCard.class);
OR
If you just annotate it with #WebService or have given it another name, then you will need to provide more information to the getPort() method:
replace
BankCard bankcard = service.getPort(BankCard.class);
with
QName port_name = new QName("http://server.bcard.soap.com/","BankCardImplPort");
BankCard bankcard = service.getPort(port_name, BankCard.class);
I am using hibernate in my web application,when I am getting exception while:
Transaction tx=session.beginTransaction();
It gives exception once in a while, I am reloading SessionFactory while catching the exception and then it runs fine.
It is working when I am reloading the SessionFactory again.
This is my code snippet:
session = HibernateFactory.openSession(0);//Passing 0 uses the existing sessionFactory
if(session.isConnected() && session.isOpen() && session!=null)
{
try{
tx = session.beginTransaction();
logger.info("Transaction is begin successfully--Transaction is--"+tx);
}catch(Exception e){
logger.info("Could not start the transaction--Transaction is--"+tx);
session = HibernateFactory.openSession(1);//passing 1 is creating new //--SessionFactory
tx = session.beginTransaction();//now this runs fine
logger.info("Inside catch--Obtained session--"+session+"and transaction--"+tx);
e.printStackTrace();
logger.error("e.getCause(): "+e.getCause());
logger.error("e.getClass(): "+e.getClass());
// throw new HibernateException(e.getMessage());
}
}
This is the stackTrace of the exception I am getting.
org.hibernate.exception.JDBCConnectionException: Cannot open connection
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:74)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:426)
at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:144)
at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:119)
at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:57)
at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1326)
at com.arosys.hibernateDao.AbstractDao.startOperation(AbstractDao.java:184)
at com.arosys.hibernateDao.AbstractDao.findAll(AbstractDao.java:150)
at com.arosys.beansDao.JobHierarchyDao.findAll(JobHierarchyDao.java:20)
at org.ArosysLogin.server.GWTJobImpl.getJobHierarchy(GWTJobImpl.java:416)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:569)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:208)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:248)
at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:861)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1584)
at java.lang.Thread.run(Thread.java:662)
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
Last packet sent to the server was 0 ms ago.
Just guessing since there isn't enough information (type and message of the exception):
Connection fails due to flaky database/network connection
do you commit your transactions? I'm not sure, but Hibernate might complain if you try to start a transaction twice.
UPDATE based on the call stack.
This seems to be a problem with the database. check out the various results for googling "com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure"
This one might help: https://serverfault.com/questions/89955/unable-to-connect-to-mysql-through-jdbc-connector-through-tomcat-or-externally
Are you sure your connections get closed after usage? I can imagine the database denying access after so many connections are opened. Checking the logs of your database might help as well.
Set ValidateConnectionOnBorrow to true
and add a validation query for SQLForValidateConnection
Set autoReconnect to true for jdbc URL
either by Server connection pool configuration or connection pool configuration.
I assume(from the stack trace) that you are using MySQL,Hibernate with either JBoss or Tomcat.
Let me know in case you face any problem, I faced the same long ago.