pcinfini
New Member
- Messages
- 11
- Reaction score
- 0
- Points
- 1
Hi, I'm SteveLikeANinja of PC Infinity, and in a Java Chat application I build, I need to now connect to a database instead of a separate account server. This is the code I use to connect:
After a while of waiting for the app to connect, I get the following...
Please help find the solution!
Code:
static final String JBDC_DRIVER="com.mysql.jdbc.Driver";
static final String DB_URL="jdbc:mysql://www.pcicrew.pcriot.com:3306/pcinfini_users";
private static final String USRNM_DB="user";
private static final String PASS_DB="pass";
Connection conn=null;
Statement stmt=null;
ResultSet rs;
private void initDB(){
try{
Class.forName("com.mysql.jdbc.Driver");
System.out.println("Connecting...");
conn = DriverManager.getConnection(DB_URL,USRNM_DB,PASS_DB);
System.out.println("Connection Established.");
stmt=conn.createStatement();
String sql="SELECT * FROM `accounts`";
rs=stmt.executeQuery(sql);
}catch(SQLException sqle){
JOptionPane.showMessageDialog(this,"MySQL Error: "+sqle.getMessage(),"MySQL Error",JOptionPane.ERROR_MESSAGE);
}catch(ClassNotFoundException cnfe){
JOptionPane.showMessageDialog(this,"MySQL JBDC Driver not supported. Sorry!", "MySQL Error",JOptionPane.ERROR_MESSAGE);
}
}
Code:
MESSAGE: java.net.ConnectionException: Connection Timed out: connect
Please help find the solution!