I want to connect to mysql db server through my localhost(PC) to remote server.
The steps i have followed to connect db server.
Step 1: I have installed jdk 1.6.29 version in my PC and also JDBC driver(mysql-connector-java-5.1.18) using windows XP3 pack
Step 2: Set the path for JDK and classpath for JDBC driver.
Step 3: The details available with me
-> Server IP address
-> Data base Name
-> User name and password
-> No port number available
Step 4: import java.sql.*;
Code:
public class DB {
// JDBC driver name and database URL
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://IP adress/Database name";
// Database credentials
static final String USER = "Umeshwar";
static final String PASS = "XXXXX";
public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
try{
//STEP 2: Register JDBC driver
Class.forName("com.mysql.jdbc.Driver").newInstance();;
//STEP 3: Open a connection
System.out.println("Connecting to database...");
conn = DriverManager.getConnection(DB_URL,USER,PASS);
//STEP 4: Execute a query
System.out.println("Creating statement...system is connected");
conn.close();
}catch(SQLException se){
//Handle errors for JDBC
se.printStackTrace();
}catch(Exception e){
//Handle errors for Class.forName
e.printStackTrace();
}
System.out.println("Goodbye!");
}//end main
}//end FirstExample
Please tell me where i was wrong.
