Java - MySQL - Connector/J - Eclipse
Ahnimus
Posts: 10,560
So, I wonder if any of you can help me.
I've never written MySQL code in Java before.
I'm using Eclipse edittor,
I have MySQL installed and created a table logsdb with values:
datetime as DATETIME
type as VARCHAR(20)
and ticket as VARCHAR(20)
User = root
Password = admin
I've downloaded and installed Connector/J as the JDBC driver.
When I write my code in Eclipse and run it, I get the error:
SQLException: No Suitable Driver Found
Within my code, I've initiated Connector/J:
import java.sql.*;
Class.forName("com.mysql.jdbc.Driver");
And, I added the Connector/J JAR file to the imports in Eclipse.
I don't get why it's not recognizing the Connector/J driver in eclipse. Similarily, I tried running a JSP from Tomcat using similar code and it locks up.
I've never written MySQL code in Java before.
I'm using Eclipse edittor,
I have MySQL installed and created a table logsdb with values:
datetime as DATETIME
type as VARCHAR(20)
and ticket as VARCHAR(20)
User = root
Password = admin
I've downloaded and installed Connector/J as the JDBC driver.
When I write my code in Eclipse and run it, I get the error:
SQLException: No Suitable Driver Found
Within my code, I've initiated Connector/J:
import java.sql.*;
Class.forName("com.mysql.jdbc.Driver");
And, I added the Connector/J JAR file to the imports in Eclipse.
I don't get why it's not recognizing the Connector/J driver in eclipse. Similarily, I tried running a JSP from Tomcat using similar code and it locks up.
I necessarily have the passion for writing this, and you have the passion for condemning me; both of us are equally fools, equally the toys of destiny. Your nature is to do harm, mine is to love truth, and to make it public in spite of you. - Voltaire
Post edited by Unknown User on
0
Comments
you might check that your versions of Tomcat, mysql, Java and your hosting platform are cross-compatible too.
Thanks.
I have all the latest versions, and followed some tutorials to set it all up, but in the end I get this error. It could just be my machine, I messed up some of my services, but I still get the MySQL and Tomcat servers running, I just can't interface them. :(
- Antwerp '06, Nijmegen '07, Werchter '07
I did find some information on editting the Tomcat server.xml and web.xml files, which I did, but it's still not working. I know the MySQL server is up, because I can log into it from a command prompt. :(
And check the tomcat logs (stderr/stdout), and the <server>.err log from mysql.
Yea, Tomcat is saying that JAVA_HOME is defined incorrectly. I have it pointing to a JRE in the windows environment variables.
JAVA_HOME = C:\Program Files\Java\JRE-1.05.04 or something like that. I'm at work right now, I can post the exact information later.
When I looked up the error SQLException: No Suitable Driver. It's apprently either the URL I'm trying to use in my script, or the CLASSPATH. I must be setting the class path wrong.
I'm having a problem with g.drawString() and g.fillOval() though.
Well, that and IE doesn't recognize my db.class inside my db.jar archive
I added the code to my index.jsp:
<applet archive=db.jar code=db.class width="400" height="400">
</applet>
Internet Explorer returns "Load: class db not found"
Here is my java code, so far (just getting used to it)
import java.util.*;
import java.applet.*;
import java.sql.*;
import java.awt.*;
public class db extends Applet
{
public void init(Graphics g)
{
Connection conn = null;
Statement statement = null;
ResultSet rs = null;
g.setFont(new Font("Arial", Font.ITALIC, 12));
g.setColor(Color.black);
g.drawString("Starting up!", 40, 75);
try
{
String string = null;
String userName = "root";
String password = "admin";
String url = "jdbc:mysql:http://localhost:3306/logsdb";
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
conn = DriverManager.getConnection (url, userName, password);
System.out.println ("Database connection established");
rs = statement.executeQuery("SELECT * FROM errors");
while (rs.next()) {
string = rs.getString("type");
g.drawString(string, 40, 85);
}
}
catch (Exception e)
{
System.err.println (e);
g.drawString("Error", 40, 85);
}
finally
{
if (conn != null)
{
try
{
conn.close ();
System.out.println ("Database connection terminated");
}
catch (Exception e) { /* ignore close errors */ }
}
}
}
public void paint(Graphics g){
}
}
Now, I had in public void paint() some code that draws a pink oval. I removed it, but still, when I load index.jsp in Firefox it draws the pink oval!!! Even after I removed all the "private data" a.k.a temporary internet files.
Maybe, because I'm not disposing of the code.
In addition to temp internet files, you might also have to clear your java cache. You can also try it with a different Windows user to make sure it's not a cache problem.