David
David

Reputation: 441

Java Applet on an Xampp Server - No suitable driver found on jdbc:mysql://localhost:3306/

I'd like to preface this question by saying that I'm really new at server setup and programming.

I made an applet that views data from tables in a MySQL database and lets just say it outputs it. It's a lot more complicated than that but the point is that the applet runs perfectly in Eclipse when I run it. I had to set the MySQL-connector-java-5.1.15-bin.jar file as an external library for it, but after doing that it runs perfectly.

The problem is whenever I put the code on my Xampp server, it doesn't work right. The applet start and everything works until the applet tries to connect to the MySQL database (Xampp) using the following code:

String connectionURL = "jdbc:mysql://127.0.0.1/";  
Connection connection = null;  
 try{  
 connection = DriverManager.getConnection(connectionURL, "root", "mypassword");  
}catch(Exception e){  
  System.out.println("Error: "+e);   
}

In the applet I didn't use System.out.println(), but I did manage to find out the I was getting was:

java.SQL.Exception: No suitable driver found on jdbc:mysql://127.0.0.1/

I'm wondering what I need to do to get around this error. Where do I need to put the .jar connector or how do I need to configure it with my Xampp server to get this to work?

Upvotes: 0

Views: 3585

Answers (2)

David
David

Reputation: 441

I fixed it!

All I had to do was this:

<applet code="file.class" archive ="mysql-connector-java-5.1.14-bin.jar" width="500" height="500">
</applet>

in the html file that I wanted to display the applet in.

Upvotes: 2

hisdrewness
hisdrewness

Reputation: 7651

To build a webapp, you would compile your code and build a WAR (Web Application Archive), which the artifact that would be deployed to your server, unpacked, and be put in your webapps folder. WEB-INF is the source folder where your web content goes in your project.

In eclipse, you should have this folder src/main/WEB-INF, where you could place CSS (Cascading Style Sheets), JavaScript files, images, JSPs, etc.

The fact that you have added the MySQL jar as an external dependency means that it would not be added to the WAR that you would be deploying.

The short answer to your question is that you need that MySQL jar to be on the classpath of your webapp, which you would do by placing it in (e.g.) tomcat/webapps/<your project name>/WEB-INF/lib, then restart tomcat (that is, if you use tomcat).

This will be a bit of a learning curve at first, but I would suggest you learn how to use Maven. Maven will allow you to consume dependencies, and build a proper WAR (pulling in these dependencies).

Guide to building a webapp with Maven.

Upvotes: 2

Related Questions