wood burning stoves 2.0*
The moose likes JDBC and the fly likes mysql driver problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "mysql driver problem" Watch "mysql driver problem" New topic
Author

mysql driver problem

wezy de wezy
Greenhorn

Joined: Nov 15, 2003
Posts: 1
Hello,
I'm trying to connect an applet to mysql database.
Here's my code :
public class DbTest extends Applet {
Connection connection;
Statement stmt;
ResultSet resultset;
public void init() {
}
public void paint(Graphics g) {
g.drawString("tspel begint", 10, 30);
try {
Class.forName("com.mysql.jdbc.Driver");
g.drawString("Driver loaded", 10, 70);
} catch (ClassNotFoundException e) {
g.drawString("Driver problem", 10, 50);
g.drawString(e.toString(), 10, 70);
}
try {
connection =
DriverManager.getConnection(
"jdbc:mysql://localhost/db",
"loginname",
"password");
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
stmt = connection.createStatement();
} catch (SQLException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
try {
resultset = stmt.executeQuery("SELECT * FROM temp");
} catch (SQLException e3) {
// TODO Auto-generated catch block
e3.printStackTrace();
}
try {
while (resultset.next()) {
System.out.println(resultset.getString("naam"));
}
} catch (SQLException e4) {
// TODO Auto-generated catch block
e4.printStackTrace();
}
}
}

I'm getting the error : java.lang.ClassNotFoundExcpetion: com.mysql.jdbc.Driver
here's my html code :
<html>
<head>
<title>Wezy's applet</title>
</head>
<body>
<applet code="DbTest.class" width=2000 height=200>
</applet>
</body>
</html>
Does anybody know why I'm getting this code and what I can do about it??
Thanks in advance
Wezy
Timothy Lovern
Greenhorn

Joined: Nov 15, 2003
Posts: 4
You will need to create an instance of the driver
The syntax looks like:
Class.forName("com.mysql.jdbc.Driver").newInstance();
This is in the readme that is part of the MySQL jar file. You should be able to extract it and there's a lot of useful information in there...
Having said that, however, I am also experiencing a similar problem - the newInstance method is failing. I suspect it is a CLASSPATH problem, but I am not certain why.
I'm using the netbeans IDE on MAC OSX (Panther)
I have the jar file mounted in the filesystem, and can browse it from the ide, but reflection is still not finding the constructors or other methods of the class.
So, I'd be happy to hear any suggestions on how to resolve this too.
thanks to all in advance!

Tim
[ November 15, 2003: Message edited by: Timothy Lovern ]
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9043
    
  10
Originally posted by wezy de wezy:
I'm getting the error : java.lang.ClassNotFoundExcpetion: com.mysql.jdbc.Driver
here's my html code :
<html>
<head>
<title>Wezy's applet</title>
</head>
<body>
<applet code="DbTest.class" width=2000 height=200>
</applet>
</body>
</html>

This is a difficult thing. First of all, You're using a plain applet html page which limits you to jdk 1.1.4 or below. At that point, java didn't have jdbc classesd.

Secondly, even if you use the java plug-in to be able to run your applet, you will probably need to make it a signed applet because you'll get a security exception.

Do you absolutely have to have an applet rather than an application?

By the way, you'll notice that at JavaRanch most people use their real names, or at least names that appear like real names. Here is a page about our policy on display names.
[ November 16, 2003: Message edited by: Marilyn de Queiroz ]

JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Mathias Nilsson
Ranch Hand

Joined: Oct 13, 2003
Posts: 107
You should use EJB to connect to the database and then use the EJB in
the Applet.
// Mathias


SCJP2 , MCP( 70-229 ) , Preparing For SCWDC
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Originally posted by Mathias Nilsson:
You should use EJB to connect to the database and then use the EJB in
the Applet.
// Mathias

You should probably back that statement up with some reasoning
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: mysql driver problem
 
Similar Threads
need some help
zip / pipedinputstream / pipedoutputstream problem
JTable serialization problem
AbstractMethodError while doing prepareCall()
java.sql.SQLException: No suitable driver