import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class OraSqlConnection {
private String url = "jdbc:oracle:thin:@localhost:1521:主机字符串";
private String user = "username";
private String password = "pwd";
private Connection conn;
public OraSqlConnection() {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection(url, user, password);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("get connection success");
}
public Connection getConnection()
{
new SqlConnectionUtil();
return this.conn;
}
public static void main(String[] args) {
new SqlConnectionUtil();
}
}
其中需要的oracle驱动是一个叫classes12.jar的包