I just talked to my host that I have my web page at and they say they allow JDBC connections.
Anyway, the page you can view this at is http://mystikrpg.com/mysqltest/mysqltry.html
Here is my error:
**** Looking for database...
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1118)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:343)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2308)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2122)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:774)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:49)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:375)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:289)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at test.init(test.java:38)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.net.SocketException: java.security.AccessControlException: access denied (java.net.SocketPermission [0:0:0:0:0:0:0:1]:4464 connect,resolve)
at com.mysql.jdbc.StandardSocketFactory.unwrapExceptionToProperClassAndThrowIt(StandardSocketFactory.java:407)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:268)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:292)
... 16 more
java.lang.NullPointerException
at test.init(test.java:69)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Exception: java.lang.NullPointerException
and here is the code:
What am I doing wrong?
//package mysqltest;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.applet.Applet;
import java.awt.TextArea.*;
import java.sql.*;
import java.util.*;
import javax.swing.plaf.*;
import javax.swing.plaf.basic.*;
import java.net.*;
import java.applet.*;
public class test extends JApplet
{
public JTextArea c;
public void init()
{
c = new JTextArea();
add(c);
c.append("**** Looking for database...");
Connection conn = null;
Properties props = new Properties();
String url = "jdbc:mysql://localhost:3306/";
String dbName = "mystik";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "";
String loggedusername = getParameter("name");
boolean online = false;
try
{
Class.forName(driver).newInstance();
online = true;
if (online)
{
// if user loads applet online
conn = DriverManager.getConnection("jdbc:mysql://localhost:4464/jsfdan_mystikdan", "jsfdan_muser", "test");
}
else
{
// for localhost - testing purposes props.put("user", "root");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mystik", props);
}
c.append("\nConnected to the database");
c.append("\nGetting stats for: " + loggedusername);
PreparedStatement statement = conn.prepareStatement( "select * from `user` where `username` = '"+loggedusername+"'");
ResultSet result = statement.executeQuery();
// just a dumb mysql statement! while(result.next())
{
c.append("\nUsername: "+result.getString(2)+ "\nLevel: "+result.getString(6)+"\nEXP: "+result.getString(8)+"\n");
}
PreparedStatement updateEXP = conn.prepareStatement( "update`user` set `exp` = '666' where `username` = '"+loggedusername+"'");
updateEXP.executeUpdate();
ResultSet xresult = statement.executeQuery();
while(xresult.next())
{
c.append("\nUsername: "+xresult.getString(2)+ "\nLevel: "+xresult.getString(6)+"\nEXP: "+xresult.getString(8)+"\n");
}
c.append("\nDisconnected from database");
}
catch (Exception e)
{
System.out.println(c.getText());
e.printStackTrace();
}finally {
try {
conn.close();
}catch(SQLException dan) {dan.printStackTrace(); }
}
}
}