Reputation: 4369
I have a terrible problem with Tomcat, well terrible because of this problem I've thrown away the project for more than a month now... Yet I'll still need to solve it and to go on with the project...
So it's throwing me this error:
java.sql.SQLException: No suitable driver found for jdbc:sqlserver://isd.ktu.lt:1433;DatabaseName=LN2012_bakDB2 java.lang.NullPointerException
The thing is that the same application is working in the desktop version perfectlz, however when it comes to the version which is supposed to be running on the server (Tomcat 7.0.22.0 inside NetBeans 7.1.2) it just throws the Error. It seems it doesn't load the pooling driver or I don't even know...
Well here's the part responsible for that:
public DatabaseConnection(Parameters params) {
// parameters and the output
this.gui = params.getGui();
// activate database pool
connectionPool = new GenericObjectPool(null);
connectionFactory = new DriverManagerConnectionFactory(params.getDbAdr(), params.getDbUser(), params.getDbPass());
poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, connectionPool, null, null, false, true);
driver = new PoolingDriver();
driver.registerPool("GenTreeDatabase", connectionPool);
//driver.registerPool("jdbc:apache:commons:dbcp:GenTreeDatabase", connectionPool);
}
public void openConn() {
if (allowOutput) gui.print("Getting connection to database");
try {
con = DriverManager.getConnection("jdbc:apache:commons:dbcp:GenTreeDatabase");
if (con != null) {
if (allowOutput) gui.print("Connection to database was successful");
}
} catch (SQLException ex) {
gui.err(specificError + "Error getting connection to database - " + ex);
}
}
It happens at the point where it tries to get the connection, then it gets a null pointer exception, since the connection is not retrieved successfuly.
I'm not familiar with Tomcat and up until this moment, Netbeans handled tomcat fine... The thing is I hate errors like this... If you don't solve it in three days, you get so frustrated and don't wanna get back to that, you feel like hitting a wall... Now I tried googling a lot about it, but still it wasn't much of a help... So I'd be really glad if somebody could help me with this. Thanks. :)
Upvotes: 7
Views: 17644
Reputation: 1
it helped me copying the mssql-jdbc-9.2.1.jre8.jar file to the C: \ Java \ jdk1.8.0_291 \ jre \ lib \ ext folder
Upvotes: 0
Reputation: 12757
I too encountered the same issue. It is because your tomcat server does not have the jar
file of your JDBC
. I fixed the problem by copying the JAR
file to lib
folder in tomcat server.
Upvotes: 0
Reputation: 4798
This is probably too late to answer this question but in order to help with similar issues, Here's how I got around it.
Quick Solution:
Copy the JDBC-driver JAR file
(mine was ojdbc6
) into $JAVA_HOME/jre/lib/ext
(for me it was C:\Program Files\Java\jdk1.7.0_80\jre\lib\ext
).
Details:
According to Apache Tomcat 7 documentations When Tomcat is started, it creates a set of class-loaders that are organized into the following parent-child relationships:
Bootstrap
|
System
|
Common
/ \
Webapp1 Webapp2 ...
Each class loader, searches for JAR files inside a certain directory. The classes and resources that they make visible are explained below:
Bootstrap : This class loader contains the basic runtime classes provided by the JVM, plus any classes from JAR files present in the System Extensions directory $JAVA_HOME/jre/lib/ext
.
System : This class loader is normally initialized from the contents of the CLASSPATH
environment variable. All such classes are visible to both Tomcat internal classes, and to web applications. However, There are some exceptions for Tomcat.
Common : This class loader contains additional classes that are made visible to both Tomcat internal classes and to all web applications. This class loader looks (by default) in $CATALINA_BASE/lib
and $CATALINA_Home/lib
for jar files.
Webapps : A class loader is created for each web application that is deployed in a single Tomcat instance. All unpacked classes and resources in the /WEB-INF/classes
directory of your web application, plus classes and resources in JAR files under the /WEB-INF/lib
directory of your web application, are made visible to this web application, but not to other ones.
ojdbc
JAR file inside $JAVA_HOME/jre/lib/ext
the JDBC driver, will get visible at the Bootstrap level. Upvotes: 1