aspose file tools*
The moose likes Websphere and the fly likes ClassNotFoundException Mysql Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Websphere
Bookmark "ClassNotFoundException Mysql" Watch "ClassNotFoundException Mysql" New topic
Author

ClassNotFoundException Mysql

Vince Black
Greenhorn

Joined: Oct 16, 2003
Posts: 4
hi !
I have a Database Connection Problem in WebSphere Studio Application Developer (Windows) Version: 5.1.0
This is my Source Code :

And i Get this Error Message :

An exception has been intercepted
java.lang.ClassNotFoundException: com.ibm.websphere.jdbcx.sqlserver.SQLServerDataSource
at java.net.URLClassLoader.findClass(URLClassLoader.java:240)
at java.lang.ClassLoader.loadClass(ClassLoader.java:516)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:441)
at java.lang.ClassLoader.loadClass(ClassLoader.java:448)
at java.lang.Class.forName1(Native Method)
at java.lang.Class.forName(Class.java:142)
at Database.main(Database.java:13)

i hope you can held me
thx
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31075
    
232

Is "com.ibm.websphere.jdbcx.sqlserver.SQLServerDataSource" in your classpath? What type of project are you trying to access it from? If it is an EJB project, you need to include the .jar/.zip file in your module dependencies. Otherwise, you need to include it in your java build path.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
Hi. Oh boy, where to start.
(1) You're not using a mysql driver. The driver class you mention is the DataDirect driver for Microsoft SQL Server -- not mySql.
(2) Don't do that! You shouldn't use DriverManager to try and instantiate a DataSource -- that doesn't work. Use WebSphere's J2EE connection pooling instead.
I'd suggest you start with one of the WebSphere tutorials and modify that to see how connection pooling works. Look in the InfoCenter under "DataSource" and it should lead you where you need to be.
Kyle


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
Sander Klooster
Greenhorn

Joined: Jul 30, 2003
Posts: 13
hi,
You can try this code to make a connection.
first make a class ConnectionManager, like this:
package dbMySql;
import java.sql.Connection;
import java.sql.DriverManager;
/**
* Sander Klooster
* This class provides access to the MYSQL database.
*/
public class ConnectionManager
{
static
{
try
{
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
} catch (Exception e)
{
e.printStackTrace(System.out);
}
}
public static Connection getConnection()
{
try
{
return DriverManager.getConnection("jdbc:mysql://localhost/sir?user=multi&password=media");
} catch (Exception e)
{
e.printStackTrace(System.out);
throw new Error("Could not resolve database connection.");
}
}
}

Then another class BusinessObject, like this:
package dbMySql;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import dbMySql.ConnectionManager;
/**
* Sander klooster.
* This class is the base class for all business objects.
*/
public abstract class BusinessObject {
abstract protected void unpackResultSet(ResultSet rs)
throws java.sql.SQLException;
/**
* This method retreives data from the database. It uses the query
* to make a ResultSet. This ResultSet is passed to the retreiveResultSet
* method which is declared in this class.
*/
protected boolean retrieveData(String query) {
try {
Connection connection = ConnectionManager.getConnection();
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(query);
if (!resultSet.next()) {
resultSet.close();
statement.close();
connection.close();
return false; // no rows in result set
} else {
unpackResultSet(resultSet);
resultSet.close();
statement.close();
connection.close();
return true;
}
} catch (Exception e) {
e.printStackTrace(java.lang.System.out);
throw new Error("Database error.");
}
}
}
You have to modify the DataBase class of course..
good luck.
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
I have to ask what kind of client you're building. Is this a class that is supposed to work with WebSphere Application Server, or simply a standalone Java class? If the former, then you need to use a DataSource to obtain the Connection. If the latter, then Sander's method will work.
In the second case, you'll also need to make sure the runtime classpath of your client (which is set through the client agent when you choose Run... in WSAD) points to the MySQL Jar files.
Kyle
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ClassNotFoundException Mysql