利用JDBC连接Oracle数据库

public class OracleDriverBase {
Connection conn=null;
Statement st = null;
ResultSet rs = null;
public Connection getConnection()
{


try {
Class.forName("oracle.jdbc.driver.OracleDriver");
//conn=DriverManager.getConnection("jdbc:oracle:thin:@10.88.20.50:1521:orcl","industrial","llyb");
conn=DriverManager.getConnection("jdbc:oracle:thin:@10.88.20.218:1521:orcl","LLYBMANAGE","xianll");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


return conn;

}

public void closeAll() {
// TODO Auto-generated method stub
if(rs!=null)
{
     try {
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(st!=null)
{
try {
st.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(conn!=null)
{
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}


}



}

你可能感兴趣的:(ORACLE)