Hi,
I'm having trouble connecting to my MySQL database from an applet. Here's the deal: I'm running on a virtual server, my page with the applet is located in such a way that it is accessible from
cPanel®, JDBC is installed (and confirmed working), but I cannot connect to my database. I've tried various ways, but I keep getting the exception:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
blah blah blah
Caused by: java.io.IOException: open HTTP connection failed.
blah blah blah
I CAN connect to the DB using Java, but only through a command prompt, using the follow code I got from a tutorial:
import java.sql.*;
public class JdbcExample1 {
public static void main(String args[]) {
Connection con = null;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection("jdbc:mysql:///test", "root", "password");
if(!con.isClosed())
System.out.println("Successfully connected to MySQL server...");
} catch(Exception e) {
System.err.println("Exception: " + e.getMessage());
} finally {
try {
if(con != null)
con.close();
} catch(SQLException e) {}
}
}
}
However, I just can't seem to get it right from the applet. Here is the relevent code from my applet, starting right after a button is pressed:
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == tailnum_okButton)
{
String tailnumber = tailnum_TextField.getText();
if (tailnumber.equals(""))
{
tailnum_Label.setForeground(Color.RED);
}
else
{
search_tailnum_Label.setText(tailnumber);
overallLayout.show(cardPanel, "2");
// Connect to the MySQL Database
Connection con = null;
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection("jdbc:mysql://localhost/test?user=root&password=password");
overallLayout.show(cardPanel, "3");
}
catch (Exception c)
{
overallLayout.show(cardPanel, "4");
c.printStackTrace();
}
finally
{
if (con != null)
{
try
{
con.close ();
System.out.println ("Database connection terminated");
}
catch (Exception c) { /* ignore close errors */ }
}
}
}
}
}
}
If anyone can help me, it would be greatly appreciated!!!
Thanks in advance,
- Jeff