Here is an example to Connect to Oracle database using jdbc driver. In the same way we can connect with any database with appropriate JDBC driver for that database
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Connector {
private String user = "scott";
private String password = "tiget";
private String connectionString = "jdbc:oracle:thin:@localhost:1521:orcl";
private String driverClass = "oracle.jdbc.driver.OracleDriver";
public Connector(){
}
public Connection connect(){
Connection connn = null;
try {
Class.forName(driverClass).newInstance();
connn = DriverManager.getConnection( connectionString, user, password);
} catch (ClassNotFoundException e) {
e.printStackTrace();
return null;
} catch (SQLException e) {
e.printStackTrace();
return null;
} catch (Exception e) {
e.printStackTrace();
return null;
}
return connn;
}
}
Java J2ME JSP J2EE Servlet Android