JDBC

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:
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);
        }
    }
After a while of waiting for the app to connect, I get the following...

Code:
MESSAGE: java.net.ConnectionException: Connection Timed out: connect

Please help find the solution!
 

essellar

Community Advocate
Community Support
Messages
3,295
Reaction score
227
Points
63
Are you using a Free hosting account? If so, remote MySQL is not available; you would need to create an HTTP API using PHP at the server.
 

pcinfini

New Member
Messages
11
Reaction score
0
Points
1
(NO PATRONIZATION INTENDED)
Sorry if I wrote that message in a seemingly sarcastic way... I didn't mean to do so but realized that it might sound like that if you read it the wrong way
:(
 

essellar

Community Advocate
Community Support
Messages
3,295
Reaction score
227
Points
63
No worries; I wouldn't have read that as snark.

No, I'm afraid not. The only avenue of direct access you have to your database is via a "localhost" connection (last I checked, you had to use the word "localhost"; even 127.0.0.1 would fail) so for anything not running on your server you need to access via HTTP. You can use JSON posted over HTTP to talk to a PHP script that responds using JSON; that's probably the easiest to build at both ends (at least as easy as XML, and certainly a lot less verbose) because you'd have JSON parsers available at both ends.

If you really need remote MySQL access, you would need to be on a paid plan (Premium shared hosting or a VPS).
 
Top