Urgent... unable to load JDBC driver
i have developed a servlet which will establish connection to mySQL.. but it couldn't load the JDBC driver even i placed
[ mysql-connector-java-2.0.14-bin.zip ] in [ C:\j2sdk1.4.2_05\jre\lib\ext\ ]
in fact.. it work fine b4 i format my notebook.. anyone can help me??
pls note that i using APACHE TOMCAT and mySQL 3.23
pls help.. very urgent one
the following is my servlet code.....
import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
public class LoginServlet extends HttpServlet {
static final String dbURL = "jdbc:mysql://localhost" ;
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
Connection conn = null;
String nextJSP = null;
try {
Class.forName("org.gjt.mm.mysql.Driver");
catch (ClassNotFoundException e) {
throw new ServletException("Unable to load JDBC driver");
}
i already add new variable in environment variables
variable name = CLASSPATH
variable value = C:\j2sdk1.4.2_05\jre\lib\ext\mysql-connector-java-2.0.14-bin.jar;
but the same output is come up.. still unable to load my JDBC driver in TOMCAT... y?
Similar Messages
-
Hello All -
I'm new to Java and I'm attempting to connect a newly created MySQL database to a simple Java application as shown here.
import java.sql.*;
public class SimpleJDBC {
public static void main(String[] args) throws SQLException, ClassNotFoundException{
// Load the JDBC driver
Class.forName("c:/Drew/JDBCon/mysql-connector-java-5.0.6-bin.jar");
System.out.println("Driver Loaded!!!");
// Establish a connection
Connection connection = DriverManager.getConnection("jdbc:mysql://root/ce_workshop");
System.out.println("Database connected");
// Create a statement
//Statement statement = connection.createStatement();
// Execute a statement
//ResultSet resultSet = statement.executeQuery("SELECT * FROM XXX");
// Iterate through the results
//while (resultSet.next())
// System.out.println(resultSet.getString(1));
// Close the connection
connection.close();
1) I've setup a the following directory in Microsoft Windows:
C:\Drew\JDBCon\
2) I've added the mysql-connector-java-5.0.6-bin.jar file to the C:\Drew\JDBCon\ directory
3) I've added the SimpleJDBC.java file to the C:\Drew\JDBCon\ directory
4) I've compiled the SimpleJDBC.java file using the following:
C:\Drew\JDBCon>javac -cp C:/Drew/JDBCon SimpleJDBC.java
5) Then I run the file:
C:\Drew\JDBCon>java -cp C:/Drew/JDBCon SimpleJDBC
But get the following error:
Exception in thread "main" java.lang.ClassNotFoundException: c:/Drew/JDBCon/mysql-connector-java-5.0.6-bin.jar
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at SimpleJDBC.main(SimpleJDBC.java:7)
I've tried many things, but nothing seems to work.
Any help is greatly appreciated!
Thanks,
DrewHi jschell,
Just a little background...
For the last 4-5 years, I've been using Microsoft Access and VBA to develop databases and small utilities to assist in certain jobs at the company I work for. Due to being a small division of a large corporation, and the reluctance for upper management to modify the purchased company databases, a small group of us started simple data extracts years ago and then uploaded the data it into Microsoft Access for both analytical and reporting purposes. As you may know, Access is very limited, and we�ve taken it far beyond the intended limit. We deliberately do not load some data tables due to the overwhelming size (2+ million records).
In the last 6 months, in my free time, I�ve taken the initiative to learn (or attempt to learn) both MySQL and Java (SQL is no problem for me). I�ve bought �Introduction to Java Programming - Comprehensive Version - 5th Edition� and read a good majority of it (some parts skimmed) along with reading a MySQL book; majority of it being SQL that I already understand and have for years.
I completed the book last week; keep in mind, not in utter detail. I had thought that I could get started with a simple application that would connect to a simple MySQL table and then build an understanding of the Java language from there.
I didn�t mention in my last post that I was able to get the MySQL driver to load and a connection established in Netbeans. I figured that instead of completely relying on Netbeans for my first real application that I should get it to work through the DOS prompt.
I realize that my understanding of Java is probably at a 3 on a scale of 1-100 right now, however that is why I�m writing to this forum. My main goal is to get the simplest possible application running using a MySQL driver and obtain a connection. I would greatly appreciate any help in getting this done, or a recommended website tutorial on creating a simple JDBC application. I�ve attempted to find these, and did, but wasn�t able to find anything that I could understand.
Also, I do understand classes and that you import, extend, or inherit them when writing programs, I just haven�t had the chance yet to practice this.
Regards,
Drew -
Cannot load JDBC driver class 'com.mysql.jdbc.Driver'
Hi,
At the moment I'm trying to get an example working. The error message I get is:
Unable to get connection, DataSource invalid: "org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.mysql.jdbc.Driver'"
The example I tried is http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html.
Configuration:
Wampserver 2.0 (Apache, MySQL, PHP for Windows XP), Tomcat 6.0 and jdk1.6.0_03.
The following files are installed in %CATALINA_HOME%/webabbs/
- Dbtest/test.jsp
- Dbtest/WEB-INF/web.xml
- Dbtest/WEB-INF/lib/standard.jar
- Dbtest/WEB-INF/lib/tomcat-dbcp.jar
- Dbtest/WEB-INF/lib/jstl.jar
Tia,
Abel.Hi,
I added the jar file containing the requested class to my lib directory. So the current contents of that directory is:
The following files are installed in %CATALINA_HOME%/webabbs/
- Dbtest/test.jsp
- Dbtest/WEB-INF/web.xml
- Dbtest/WEB-INF/lib/standard.jar
- Dbtest/WEB-INF/lib/tomcat-dbcp.jar
- Dbtest/WEB-INF/lib/jstl.jar
- Dbtest/WEB-INF/lib/mysql-connector-java-5.1.5-bin.jar
More importantly, I started my Wamp server.
The example works as it should have. Thanks for the feedback.
Abel -
Torrentflux 2.4 (ADONewConnection: Unable to load database driver)
I'm trying to setup Torrentflux 2.4 on my server.
I used the torrentflux PKGBUILD vom AUR: http://aur.archlinux.org/packages.php?ID=1664
I set up Apache/MySQL/PHP following the guide. PHP test script is working fine:
<?php phpinfo(); ?>
I setup a symbolic link from /srv/http to my /opt/torrentflux
ls /srv/http/
insgesamt 4
-r--r--r-- 1 root root 20 6. Mär 21:23 test.php
lrwxrwxrwx 1 root root 17 6. Mär 21:07 torrentflux -> /opt/torrentflux/
When I try to open /torrentflux/login.php in my webbrowser it says
ADONewConnection: Unable to load database driver ''
I left the default in torrentflux' config.php:
$cfg["db_type"] = "mysql"; // mysql, postgres7, postgres8 view adodb/drivers/
ls /opt/torrentflux/adodb/drivers/
insgesamt 532
-r--r--r-- 1 root daemon 20476 6. Mär 20:44 adodb-mysql.inc.php
-r--r--r-- 1 root daemon 25340 6. Mär 20:44 adodb-mysqli.inc.php
-r--r--r-- 1 root daemon 3220 6. Mär 20:44 adodb-mysqlt.inc.php
I'm pretty new to the whole LAMP stuff, so can please any1 tell me what's going wrong?Ok, some questions:
1. Did you enable mysql in php.ini?
http://wiki.archlinux.org/index.php/LAMP#MySQL
2. Did you read / follow the torrentflux installation guide included with the installation?
(if not, check here: http://www.torrentflux.com/)
3. I have not worked with the package from AUR, the package form the official site (again, http://www.torrentflux.com/) works well for me. Did you try this? -
Unable to Load USB Driver in LV for Total Phase's Aardvark I2C adaptor
I have tried to instal Total Phase's Aardvark I2C USB driver for LabVIEW on two computers and two versions of LV (8.5 and 7.1) without success. The Windows driver seems to be working fine as their command center gui terminal-esque program works without a hitch, but the LV DLL doesn't seem to work.
Attached is the very simple vi to find connected Aardvark USB devices (aa_find_devices). It always returns the same error code, 8002, which resolves to:
AA_UNABLE_TO_LOAD_DRIVER
-2
unable to load USB driver
From their documentation: http://www.totalphase.com/docs/aardvark_datasheet/sect005/#s5.9
This looks like perhaps the LabVIEW DL, "aardvark.dll" maybe having a versioning issue. So my question is this: Using LabVIEW, how does one debug dll dependencies and resolve issues like this? Do I need the source code for the lib?
Cheers,
Joe Gorse
Solved!
Go to Solution.
Attachments:
find_devices.vi 11 KBDear Joe,
Let me start off by apologizing for the inconvenience you
have gone through. I am an engineer at Total Phase. We are
working on fixing this issue for our next release of the
Aardvark LabVIEW Driver. This forum post was only brought
to our attention today. In the future, you can also let
Total Phase know about these kinds of issues by emailing
[email protected] We are very responsive through
email or phone.
The problem you are experiencing has to do with versioning
issues between our DLL and USB driver. Specifically, DLLs
before v5.xx must use the older version of our USB driver.
By replacing the DLL from our latest version of Control
Center, you have effectively upgraded the DLL that the
LabVIEW driver is using and made it compatible with v2.xx of
the USB driver.
The most likely reason that smercurio_fc did not see a
difference between the DLL in Aardvark Control Center and
the LabVIEW driver is because he is using an older version
of Control Center and correspondingly an older version of
the USB driver.
The reason that we have not packaged the LabVIEW driver with
latest DLL is due to the fact that a few functions have
changed their function prototypes (for example aa_open_ext
and aa_spi_write), and the VIs have not yet been updated
accordingly. Although updating the DLL solved your USB
driver issue, it introduced this new issue. If you try to
use these certain VIs, LabVIEW will error out.
We are currently working on updating the LabVIEW drivers to
work cohesively with the new DLL and USB driver, and this
should be available soon. If you need immediate
availability to the functions with new prototypes you will
have to change it manually. The other recommended option is
to simply revert back to the DLL that is packaged with our
LabVIEW driver and downgrade the USB driver back to v1.xx.
I will make sure to post again once the update is released,
and I once again apologize for the inconvenience.
Best regards,
Etai -
Hi,
I have an rpt file developed in crystal report 2008. it connects to SQL Server using ODBC(RDO) connection. I have a jsp file that needs to change the datasource to use JDBC (JNDI). The scriptlet for changing datasource is given below. I have my sqljdbc.jar in the web-inf\lib folder of my application as well as in \server\{server_name}\lib folder. when I try to run the jsp it gives me error as follows :
ERROR [com.businessobjects.reports.sdk.JRCCommunicationAdapter] detected an exception: Error loading JDBC driver. The class 'com.microsoft.jdbc.sqlserver.SQLServerDriver' could not be found.
at com.crystaldecisions.reports.queryengine.Connection.t1(Unknown Source)
at com.crystaldecisions.reports.dataengine.dfadapter.DFAdapter.a(Unknown Source)
at com.crystaldecisions.reports.dataengine.dfadapter.DFAdapter.for(Unknown Source)
at com.crystaldecisions.reports.reportdefinition.ReportHelper.a(Unknown Source)
at com.businessobjects.reports.sdk.requesthandler.ReportViewingRequestHandler.long(Unknown Source)
at com.businessobjects.reports.sdk.requesthandler.ReportViewingRequestHandler.a(Unknown Source)
at com.businessobjects.reports.sdk.requesthandler.ReportViewingRequestHandler.byte(Unknown Source)
at com.businessobjects.reports.sdk.JRCCommunicationAdapter.do(Unknown Source)
at com.businessobjects.reports.sdk.JRCCommunicationAdapter.if(Unknown Source)
at com.businessobjects.reports.sdk.JRCCommunicationAdapter.a(Unknown Source)
at com.businessobjects.reports.sdk.JRCCommunicationAdapter$2.a(Unknown Source)
at com.businessobjects.reports.sdk.JRCCommunicationAdapter$2.call(Unknown Source)
at com.crystaldecisions.reports.common.ThreadGuard.syncExecute(Unknown Source)
at com.businessobjects.reports.sdk.JRCCommunicationAdapter.for(Unknown Source)
at com.businessobjects.reports.sdk.JRCCommunicationAdapter.int(Unknown Source)
at com.businessobjects.reports.sdk.JRCCommunicationAdapter.request(Unknown Source)
at com.businessobjects.sdk.erom.jrc.a.a(Unknown Source)
at com.businessobjects.sdk.erom.jrc.a.execute(Unknown Source)
at com.crystaldecisions.proxy.remoteagent.RemoteAgent$a.execute(Unknown Source)
at com.crystaldecisions.proxy.remoteagent.CommunicationChannel.a(Unknown Source)
at com.crystaldecisions.proxy.remoteagent.RemoteAgent.a(Unknown Source)
at com.crystaldecisions.sdk.occa.report.application.ds.a(Unknown Source)
at com.crystaldecisions.sdk.occa.report.application.ReportSource.a(Unknown Source)
at ....
<br>
<br>
Scriptlet :
<%
//Report can be opened from the relative location specified in the CRConfig.xml, or the report location
//tag can be removed to open the reports as Java resources or using an absolute path (absolute path not recommended
//for Web applications).
final String DBUSERNAME = "sa";
final String DBPASSWORD = "password";
final String CONNECTION_STRING = "!com.microsoft.jdbc.sqlserver.SQLServerDriver!jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=;user=;password=";
final String TRUSTEDCON = "false";
final String PREQESERVERNAME = "jdbc:microsoft:sqlserver://localhost:1433";
final String SERVERTYPE = "JDBC (JNDI)";
final String DATABASE_DLL = "crdb_jdbc.dll";
final String DATABASE = "bssc";
final String DBCLASSNAME = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
final String USEJDBC = "true";
final String DATABASE_NAME = "bssc";
final String SERVERNAME = "jdbc:microsoft:sqlserver://localhost:1433";
final String CONNECTIONURL = "jdbc:microsoft:sqlserver://localhost:1433";
final String SERVER = "localhost";
%>
<%
final Logger logger = Logger.getLogger(ReportAction.class.getName());
final String REPORT_NAME = "../reports/Krt.rpt";
try {
ReportClientDocument oReportClientDocument = new ReportClientDocument();
oReportClientDocument.open(REPORT_NAME, 0);
// Create the two connectioninfo objects to use
IConnectionInfo oldConnectionInfo = new ConnectionInfo();
IConnectionInfo newConnectionInfo = new ConnectionInfo();
// Assign the old Connection info to the reports current info
DatabaseController dbController = oReportClientDocument.getDatabaseController();
oldConnectionInfo = dbController.getConnectionInfos(null).getConnectionInfo(0);
// If this connection needed parameters, we would use this field.
Fields pFields = null;
// Create a new propertybag for the new location
PropertyBag boPropertyBag1 = new PropertyBag();
// Set new table logon properties
boPropertyBag1.put("JDBC Connection String", CONNECTION_STRING);
boPropertyBag1.put("Trusted_Connection", TRUSTEDCON);
boPropertyBag1.put("PreQEServerName", PREQESERVERNAME);
boPropertyBag1.put("Server Type", SERVERTYPE);
boPropertyBag1.put("Database DLL", DATABASE_DLL);
boPropertyBag1.put("Database", DATABASE);
boPropertyBag1.put("Database Class Name", DBCLASSNAME);
boPropertyBag1.put("Use JDBC", USEJDBC);
boPropertyBag1.put("Database Name", DATABASE_NAME);
boPropertyBag1.put("Server Name", SERVERNAME);
boPropertyBag1.put("Connection URL", CONNECTIONURL);
boPropertyBag1.put("Server", SERVER);
// Assign the properties to the connection info
newConnectionInfo.setAttributes(boPropertyBag1);
// Set the DB Username and Pwd
newConnectionInfo.setUserName(DBUSERNAME);
newConnectionInfo.setPassword(DBPASSWORD);
// The Kind of connectionInfos is SQL
newConnectionInfo.setKind(ConnectionInfoKind.SQL);
// set the parameters to replace.
// The 4 options are:
// _doNotVerifyDB
// _ignoreCurrentTableQualifiers
// _mapFieldByRowsetPosition
// _useDefault
int replaceParams = DBOptions._ignoreCurrentTableQualifiers + DBOptions._doNotVerifyDB;
// Now replace the connections
dbController.replaceConnection(oldConnectionInfo, newConnectionInfo, pFields, replaceParams);
%>
<%
//Report can be opened from the relative location specified in the CRConfig.xml, or the report location
//tag can be removed to open the reports as Java resources or using an absolute path (absolute path not recommended
//for Web applications).
final String DBUSERNAME = "sa";
final String DBPASSWORD = "password";
final String CONNECTION_STRING = "!com.microsoft.jdbc.sqlserver.SQLServerDriver!jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=;user=;password=";
final String TRUSTEDCON = "false";
final String PREQESERVERNAME = "jdbc:microsoft:sqlserver://localhost:1433";
final String SERVERTYPE = "JDBC (JNDI)";
final String DATABASE_DLL = "crdb_jdbc.dll";
final String DATABASE = "bssc";
final String DBCLASSNAME = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
final String USEJDBC = "true";
final String DATABASE_NAME = "bssc";
final String SERVERNAME = "jdbc:microsoft:sqlserver://localhost:1433";
final String CONNECTIONURL = "jdbc:microsoft:sqlserver://localhost:1433";
final String SERVER = "localhost";
%>
<%
final Logger logger = Logger.getLogger(ReportAction.class.getName());
final String REPORT_NAME = "../reports/Krt.rpt";
try {
ReportClientDocument oReportClientDocument = new ReportClientDocument();
oReportClientDocument.open(REPORT_NAME, 0);
// Create the two connectioninfo objects to use
IConnectionInfo oldConnectionInfo = new ConnectionInfo();
IConnectionInfo newConnectionInfo = new ConnectionInfo();
// Assign the old Connection info to the reports current info
DatabaseController dbController = oReportClientDocument.getDatabaseController();
oldConnectionInfo = dbController.getConnectionInfos(null).getConnectionInfo(0);
// If this connection needed parameters, we would use this field.
Fields pFields = null;
// Create a new propertybag for the new location
PropertyBag boPropertyBag1 = new PropertyBag();
// Set new table logon properties
boPropertyBag1.put("JDBC Connection String", CONNECTION_STRING);
boPropertyBag1.put("Trusted_Connection", TRUSTEDCON);
boPropertyBag1.put("PreQEServerName", PREQESERVERNAME);
boPropertyBag1.put("Server Type", SERVERTYPE);
boPropertyBag1.put("Database DLL", DATABASE_DLL);
boPropertyBag1.put("Database", DATABASE);
boPropertyBag1.put("Database Class Name", DBCLASSNAME);
boPropertyBag1.put("Use JDBC", USEJDBC);
boPropertyBag1.put("Database Name", DATABASE_NAME);
boPropertyBag1.put("Server Name", SERVERNAME);
boPropertyBag1.put("Connection URL", CONNECTIONURL);
boPropertyBag1.put("Server", SERVER);
// Assign the properties to the connection info
newConnectionInfo.setAttributes(boPropertyBag1);
// Set the DB Username and Pwd
newConnectionInfo.setUserName(DBUSERNAME);
newConnectionInfo.setPassword(DBPASSWORD);
// The Kind of connectionInfos is SQL
newConnectionInfo.setKind(ConnectionInfoKind.SQL);
// set the parameters to replace.
// The 4 options are:
// _doNotVerifyDB
// _ignoreCurrentTableQualifiers
// _mapFieldByRowsetPosition
// _useDefault
int replaceParams = DBOptions._ignoreCurrentTableQualifiers + DBOptions._doNotVerifyDB;
// Now replace the connections
dbController.replaceConnection(oldConnectionInfo, newConnectionInfo, pFields, replaceParams);
%>
I am not sure why it is not able to get the Driver since the required jar is there in lib folder? Am I missing something ?
Edited by: sb-onward on Jul 30, 2009 6:01 PMHi,
Make sure you have set the Classpath in CRConfig.xml for the jdbc jar.
Place the CrConfig.xml in the classes directory of your application.
Please let me know the results.
Regards,
Neeraj -
Sun IDM Repositor Configuration Error: Failed to load JDBC Driver
Hi Gurus,
I am new to Java IDM and predictably failed in my first attempt to install Java IDM in a Windows machine with SQL Server 2000 SP3.
I followed the Installation document step by step and I think I din' t miss any!!.. But still I got caught by an error, here it is:
I successfully installed IDM but failed while configuring Repository. I have downloaded the JDBC driver from Microsoft for SQL Server 2000, SP3. Then after that I copied the Jar from JDBC driver folder to
%WSHOME%/bin/lib folder. After this I launched the Repository configuration setup.
I got the following error while trying to connect the waveset database with Repository type as SQL Server (JDBC Driver)
com.waveset.util.ConfigurationError: Failed to load JDBC Driver 'com.microsoft.sqlserver.jdbc.SQLServerDriver':
==> java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
The Parameters that I have given for connection are:
URL: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=waveset
JDBC Driver: com.microsoft.sqlserver.jdbc.SQLServerDriver
Connect as User: waveset
Connect Password: waveset
I have created the database and granted all access to user waveset.
Please help me come out of this. I tried dropping and recreating the database with a different name. Still it did not work, looks like it is a JDBC driver specific issue. Please guide me if I did anything wrong.
Appreciate any help
ThanksOpen your driver jar using winzip or something and check if the class: com.microsoft.sqlserver.jdbc.SQLServerDriver is present in the jar. I think you need to use a different class name. or your jar file is wrong. I think there are separate jars for SQL server 2000 and for SQL Server 2005.
-
Beginner Has Problem With Loading JDBC Driver Using MySQL
Hi, I am having problem with loading JDBC driver, and need your diagnotic help.
1. I have installed MySQL (C:\mysql), created a databse (soup), and created a littel table (VIDEOS). I am able to see the table in the console:
sql> select * from videos
2. I have downloaded the latest version of Connector/J (mysql-connector-java-3.1.0-alpha.zip), and unzip the zip file into my C:\ directory.
3. I copied the mysql-connector-java-3.1.0-alpha-bin.jar to the C:\j2sdk1.4.1_02\jre\lib\ext folder and it is in my CLASSPATH
4. MySQL server is running
C:\> C:\mysql\bin\mysqld-nt --standalone
5. open another DOS window and use the database
mysql>USE SOUP
6. succesfully compiled a Java program (javac Test.java):
import java.sql.* ;
public class Test
public static void main( String[] args )
try
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
try
Connection con = DriverManager.getConnection( "jdbc:mysql://localhost:3306/soup" );
try
Statement statement = con.createStatement();
ResultSet rs = statement.executeQuery("SELECT TITLE FROM VIDEOS");
while ( rs.next() )
System.out.println( rs.getString( "TITLE" ) );
rs.close();
statement.close();
catch ( SQLException e )
System.out.println( "JDBC error: " + e );
finally
con.close();
catch( SQLException e )
System.out.println( "could not get JDBC connection: " + e );
catch( Exception e )
System.out.println( "could not load JDBC driver: " + e );
7. when I run the Java program (java Test), I got
the message:
could not load JDBC driver: java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver
What am I missing?Hi,
I missed to specify test in my last post.
Try running your program by explicitly setting the classspath when
running your program . java -classpath c:\mysql-connector-java-3.1.0-alpha-bin.jar test
Make sure your jar file contains org.gjt.mm.mysql.Driver class -
Java.sql.SQLException: Cannot load JDBC driver class 'null'
Hi,
I am a beginner of using jdbc, i use the tomcat4.1.x, mysql3.23.54 and it's jdbc driver 2.0.14. I place the drive <in jar file> in tomcat/commons/lib and configure the server.xml, web.xml and some testing coding. But there are some error like the following:
java.sql.SQLException: Cannot load JDBC driver class 'null'
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:529)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:312)
at foo.DBTest.init(DBTest.java:18)
at org.apache.jsp.test_jsp._jspService(test_jsp.java:48)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:136)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:204)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:289)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:240)
of course its some of the error code and there are more.
Why I have this problems and how can I fix it? Can someone help me??
Thanks,
Tong
I place my test.jsp at tomcat/webapps/DBTest and DBTest.java at tomcat/webapps/DBTest/WEB-INF/classes/foo
additional of the tomcat/conf/server.xml
<Resource name="TestDB" auth="Container" type="javax.sql.DataSource" description="MySQL TestDB"/>
<ResourceParams name="TestDB">
<parameter><name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter><name>maxActive</name><value>10</value></parameter>
<parameter><name>maxIdle</name><value>1</value></parameter>
<parameter><name>maxWait</name><value>10000</value></parameter>
<parameter><name>username</name><value>javauser</value></parameter>
<parameter><name>password</name><value>javadude</value></parameter>
<parameter>
<name>driverClassName</name>
<value>org.gjt.mm.mysql.Driver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:mysql://localhost:3306/javatest?autoReconnect=true</value>
</parameter>
</ResourceParams>
tomcat/webapps/DBTest/WEB-INF/web.xml :
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<description>MySQL Test App</description>
</web-app>Post the part of your code that loads the driver and connects. My guess is you are using a variable for the name of the driver and the variable has not been set to anything(intially set to null).
Thanks
Cardwell -
Java.sql.SQLException: Cannot load JDBC driver
THis topic has been discussed many many times but I still not able to connect to Oracle 8i from my servlet using Tomcat 4.1.12 on hp-ux and java1.3
I always got: java.sql.SQLException: Cannot load JDBC driver class 'null'
In server.xml:
<Context Path="/MyApp" docBase="MyApp" debug="0" reloadable="true" >
<Resource name="jdbc/ora" auth="Container" type="javax.sql.DataSource"/> <ResourceParams name="jdbc/ora" >
<parameter>
<name>username</name>
<value>myname</value>
</parameter>
<parameter> <name>password</name>
<value>mypassword</value>
</parameter>
<parameter> <name>driverClassName</name>
<value>oracle.jdbc.driver.OracleDriver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:oracle:thin:@myhostname:1521:ora</value>
</parameter> </ResourceParams>
</Context>
In MyApp/WEB-INF/web.xml:
<resource-ref>
<res-ref-name>jdbc/ora</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
The Oracle jdbc jar file classes12.jar is under common/lib in Tomcat's home. read Permission is there.
In the servlet:
init(ServletConfig config):
Context init = new InitialContext();
Context ctx = (Context) init.lookup("java:comp/env");
dataSource = (DataSource) ctx.lookup("jdbc/acdb");
doPost(..)
the error occured at :
synchronized (dataSource){
con = dataSource.getConnection();}
Thanks in advance!Everything looks correct to me, except for one thing.
In your web.xml you have this:
<res-ref-name>jdbc/ora</res-ref-name> In your server.xml, you have this tag, which matches your web.xml:
<ResourceParams name="jdbc/ora" > But in your Java code, you've got this:
dataSource = (DataSource) ctx.lookup("jdbc/acdb"); When I've successfully set up a Web app data source, all three names had to agree. You either need to change your Java lookup name to "jdbc/ora" or change the web.xml and server.xml to "jdbc/acdb".
See if that does it. Everything else sounds correct to me. - MOD -
Can't load jdbc driver in servlet
Dear All,
I have tried to connect to MS SQL SERVER 2000 through JDBC DRIVER FOR
SQLSERVER. However I receieved an error: can't load jdbc driver class:
null.
The following steps were what I did:
1.Set up SQL Server and create a few tables and users.
2.Config Server.xml
Add the following codes in /tomcat/conf/Server.xml
<Context path="/persistence" docBase="persistence" debug="0"
reloadable="true">
<Resource name="jdbc/persistenceDB" auth="Container"
type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/PersistenceDB">
<Parameter>
<name>user</name>
<value>kitty</value>
</Parameter>
<Parameter>
<name>password</name>
<value>abc</value>
</Parameter>
<Parameter>
<name>driverClassName</name>
<value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value>
</Parameter>
<Parameter>
<name>url</name>
<value>jdbc:microsoft:sqlserver://localhost:1433;databaseName=persistence;selectMethod=cursor;</value>
</Parameter>
</ResourceParams>
</Context>
3.Config my web application's web.xml
Added the following piece of code in WEB.XML
<resource-ref>
<res-ref-name>jdbc/persistenceDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
4.Use Datasource in my code
package persistence.database;
import java.sql.*;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import javax.servlet.ServletContext;
import persistence.*;
import com.microsoft.jdbcx.sqlserver.*;
import javax.naming.Context;
public class DatabaseAuthenticator implements Authenticator {
private DataSource ds;
public void init(ServletContext sctx) throws Exception {
InitialContext init = new InitialContext();
try{
Context ctx = (Context) init.lookup("java:/comp/env");
ds = (DataSource) ctx.lookup("jdbc/persistenceDB");
} catch (Exception e) { e.printStackTrace();
public User authenticate(String username, String password)
throws AuthenticationException, UnknownException {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs;
try {
if (ds != null) {System.out.println("Success to get
datasource");
} else {System.out.println("Failed");}
System.out.println(ds.toString());
try
conn = ds.getConnection();
catch (Exception e)
e.printStackTrace();
pstmt = conn.prepareStatement("SELECT user_id " + .........
5. put msutil.jar, mssqlserver.jar and msbase.jar under /tomcat/common/lib/.
When I tried to run the program, I receieved an error: can't load jdbc
driver class: null.
I've got no idea what's going on.
Any Suggestion?
Thanks in advance
KittyHi Kitty,
The connection you're trying to set up points to nothing :
Connection conn = null;
So, you receive a complaint that that driver cannot be loaded. Please read
http://java.sun.com/docs/books/tutorial/jdbc/basics/connecting.html
download the right database driver and use that. Good luck!
Wouter van Reeven
public User authenticate(String username, String
g password)
throws AuthenticationException, UnknownException
ption {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs; -
VDS didn't start: Could not load JDBC driver
Hello,
I want to start the VDS Tutorial, but I get an error:
Exception: Data source 'Derby database' failed. Check your CLASSPATH! (in Tools
-> Options) Could not load JDBC driver 'org.apache.derby.jdbc.EmbeddedDriver'
Shutting down...
Data source 'Derby database' failed. Check your CLASSPATH! (in Tools -> Options)
Could not load JDBC driver 'org.apache.derby.jdbc.EmbeddedDriver'
But I add the derby.jar file in the VDS under Tools - Options - Classpath
Have you any ideas...?!I try to start the server without the tutorial and that works...
-
Initialization error: Loading jdbc driver
Hi ,
In a file-XI-JDBC scenario, i am getting this error. "Initialization error: Loading jdbc driver 'com.microsoft.jdbc.sqlserver.SQLServerDriver' failed: java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver".
but i have installed/deployed third party SQL driver on J2ee server thru SDM.
Can any one sort out this problem.
Rgds
SridharHi,
try looking into the log viewer in Vsual Administrator. Usually you can find more information about the problem there.
Also try redeploying the driver again.
cheers,
naveen -
hi all :)
i'm using a datasource (tomcat 4.1.18 with jdk 1.4)
i'm the following error :
java.sql.SQLException: Cannot load JDBC driver class 'null'my classes12.jar find in $CATALINA_HOME/common/lib
where is ma error ?
thanks a lot.GlobalNamingResources?
I sent up a data source for each app, like this:
<Context path="/api-prototype"
docBase="api-prototype.war"
debug="1"
reloadable="true"
crossContext="true"
useNaming="true">
<Logger className="org.apache.catalina.logger.FileLogger"
prefix="localhost-api-prototype-log."
suffix=".txt"
timestamp="true"/>
<Resource name="jdbc/APIPrototype"
auth="Container"
type="javax.sql.DataSource"/>
<!-- Oracle 9.2.0.1 data source -->
<ResourceParams name="jdbc/APIPrototype">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>oracle.jdbc.driver.OracleDriver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:oracle:thin:@elvis:1521:CAPP</value>
</parameter>
<parameter>
<name>username</name>
<value>api</value>
</parameter>
<parameter>
<name>password</name>
<value>mod</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>20</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>0</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>60000</value>
</parameter>
<parameter>
<name>removeAbandoned</name>
<value>true</value>
</parameter>
<parameter>
<name>removeAbandonedTimeout</name>
<value>300</value>
</parameter>
</ResourceParams>
</Context>This works fine on Tomcat 4.1.24. I don't know where you got that example from, but I'd recommend that you look at the Tomcat JNDI How-to:
http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-howto.html
Why go anywhere else? - MOD -
Hi all,
I'm trying to load mysql jdbc driver in runtime i've tried the following links
[http://dev-loki.blogspot.com/2008/01/loading-jdbc-driver-at-runtime.html]
[http://www.kfu.com/~nsayer/Java/dyn-jdbc.html]
[http://www.devdaily.com/java/edu/JDBC-SQLProcessor/Simple_JDBC_Example.shtml]
[http://tech.puredanger.com/2006/11/09/classloader/]
[http://fdt.powerflasher.com/blog/?p=35]
I'm not being able to get this to work it always given the classnotfoundexception
can anyone help please?
Thanks in advanceThere is no server. I'm doing a normal java aplication, i wanted to have a folder where would be the jdbc drivers in runtime the user will choose what driver to load to access a some db.
I'm using eclipse and this is what i have now
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverPropertyInfo;
import java.sql.SQLException;
import java.util.Properties;
public class DriverShim implements Driver{
private Driver driver;
public DriverShim(Driver d) {
this.driver = d;
public boolean acceptsURL(String u) throws SQLException {
return this.driver.acceptsURL(u);
public Connection connect(String u, Properties p) throws SQLException {
return this.driver.connect(u, p);
public int getMajorVersion() {
return this.driver.getMajorVersion();
public int getMinorVersion() {
return this.driver.getMinorVersion();
public DriverPropertyInfo[] getPropertyInfo(String u, Properties p) throws SQLException {
return this.driver.getPropertyInfo(u, p);
public boolean jdbcCompliant() {
return this.driver.jdbcCompliant();
String libraryPath = System.getProperty("java.library.path");
String sep = System.getProperty("path.separator");
libraryPath = "." + sep + "C:/Users/Luis/Documents/eclipse/workspace/DBDIGGER/lib/connectors" + sep + "native" + sep + libraryPath;
//libraryPath ="C:/Users/Luis/Documents/eclipse/workspace/DBDIGGER/lib/connectors";
System.setProperty("java.library.path", libraryPath);
System.out.println(libraryPath);
URL u;
try {
u = new URL("jar:file://C:/Users/Luis/Documents/eclipse/workspace/DB/lib/connectors/mysql-connector-java-5.1.7-bin.jar!/");
String classname = Settings.MYSQL;
URLClassLoader ucl = new URLClassLoader(new URL[] { u });
URL[] ee =ucl.getURLs();
Driver d = (Driver)Class.forName(classname, true, ucl).newInstance();
DriverManager.registerDriver(new DriverShim(d));
DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql", "user", "pw");
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} Project Folder Structure
DB
bin
lib
connectors
mysql-connector-java-5.1.7-bin.jar
src
result of classpath
.;C:/Users/Luis/Documents/eclipse/workspace/DBDIGGER/lib/connectors;native;C:\Program Files\Java\jre6\bin;.;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jre6/bin/client;C:/Program Files/Java/jre6/bin;C:\Program Files\JavaFX\javafx-sdk1.1\bin;C:\Program Files\JavaFX\javafx-sdk1.1\emulator\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files\Intel\DMIX;C:\Program Files\Softex\OmniPass;C:\Program Files\MySQL\MySQL Server 5.1\bin
Maybe what i'm doing wrong is the classpath, this is not a web app is a standard java aplication...
Could someone explain to me how to set a classpath ?? correctly...
Maybe you are looking for
-
Bonjour - Connect Windows 7 to external hard drive on Airport Extreme
I have to use a laptop with windows 7 for work and I want to back up to a hard drive that is connected to my airport extreme station. I downloaded the bonjour print services and I had the printer set up in a minute. I can't figure out how to connect
-
Need help reading an internal table
Howdy, I have an internal table (itab_knvh) that contains all the entries from table KNVH for a specified sales area. Now I have another internal table (itab_kunnr) that contains all the customers that I need data for. How can I read all the entries
-
How can I watch the HD version on apple tv?
I downloaded an HD Movie from itunes (purchase not rental) but when I go to watch it on my appleTV only the SD version is available.
-
Alternatives can only be used once?
Hi In the Adobe form when creating an alternative I've discovered that it can only be used once. Is this correct? I've created an alternative e.g. name = FLAG_IS_X condition flag = X. When I use the alternative 'FLAG_IS_X' the first time it works as
-
Can't read iTunes voucher code!!!
HI, MY KIDS KEEP GETTING ITUNES VOUCHER FOR THEIR BIRTHDAYS AND YESTERDAY WE RECEIVED ANOTHER ONE. THIS IS THE THIRD ONE IN TWO MONTHS THAT HAD A COMPLETELY ILLEGBILE CODE - THERE IS NO PART OF IT WE CAN READ. WE HAD TO THROW THE FIRST 2 AWAY AS TH