Mitch1234
06-15-2009, 05:53 PM
If the code below were on an applet launched remotely it would not work because the localhost does not contain the DB. What would the proper "String url =" be to connect remotely to my DB for my site.
Site: www.novajobseeker.com
DB name: novajobs_customer
Table name: CustomerInfo
Please anyone that knows how to connect remotly within java please respond. Thanks :D
Also will I need to add "Remote Database Access Hosts". The remote connection will just be any IP on the internet.
import java.sql.*;
public class JDBCDemo {
public static void main( String[] args ) {
try {
// Connect to the database
Class.forName("org.gjt.mm.mysql.Driver");
String url = "jdbc:mysql://localhost/northwind";
Connection con = DriverManager.getConnection(url, "USERNAME", "PASSWORD");
// Execute the SQL statement
Statement stmt = con.createStatement();
ResultSet resultSet = stmt.executeQuery("SELECT * from customers");
System.out.println("Got results!");
// Loop thru all the rows
while( resultSet.next() ) {
String data = resultSet.getString( "CompanyName" );
System.out.println( data );
}
stmt.close();
}
catch( Exception e ) {
System.out.println(e.getMessage());
e.printStackTrace();
}
}
}
Site: www.novajobseeker.com
DB name: novajobs_customer
Table name: CustomerInfo
Please anyone that knows how to connect remotly within java please respond. Thanks :D
Also will I need to add "Remote Database Access Hosts". The remote connection will just be any IP on the internet.
import java.sql.*;
public class JDBCDemo {
public static void main( String[] args ) {
try {
// Connect to the database
Class.forName("org.gjt.mm.mysql.Driver");
String url = "jdbc:mysql://localhost/northwind";
Connection con = DriverManager.getConnection(url, "USERNAME", "PASSWORD");
// Execute the SQL statement
Statement stmt = con.createStatement();
ResultSet resultSet = stmt.executeQuery("SELECT * from customers");
System.out.println("Got results!");
// Loop thru all the rows
while( resultSet.next() ) {
String data = resultSet.getString( "CompanyName" );
System.out.println( data );
}
stmt.close();
}
catch( Exception e ) {
System.out.println(e.getMessage());
e.printStackTrace();
}
}
}