Description
In Java programimng, how do I use Java Database to connect to a database I have online through a hosting account?
I need to connect and do a select statement to display the data.

Explanation & Answer

public Connection getConnection() throws SQLException {
Connection conn = null;
Properties connectionProps = new Properties();
connectionProps.put("user", this.userName);
connectionProps.put("password", this.password);
if (this.dbms.equals("mysql")) {
conn = DriverManager.getConnection(
"jdbc:" + this.dbms + "://" +
this.serverName +
":" + this.portNumber + "/",
connectionProps);
} else if (this.dbms.equals("derby")) {
conn = DriverManager.getConnection(
"jdbc:" + this.dbms + ":" +
this.dbName +
";create=true",
connectionProps);
}
System.out.println("Connected to database");
return conn;
}
Check out this page: http://docs.oracle.com/javase/tutorial/jdbc/basics/connecting.html
Are you using MYSQL?
