final String DRIVER="oracle.jdbc.OracleDriver";
final String URL="jdbc:oracle:thin:@localhost:1521:orcl";
final String NAME="scott";
final String PASSWORD="tiger";
protected Connection con;
protected PreparedStatement pst;
protected Statement st;
protected ResultSet rs;
//连接数据库
public Connection getConnection(){
try {
Class.forName(DRIVER);
con=DriverManager.getConnection(URL, NAME, PASSWORD);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return con;
}
//关闭资源
public boolean closeNews(){
if(rs!=null)
try {
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
if(st!=null)
try {
st.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
if(pst!=null)
try {
pst.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
if(con!=null)
try {
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
return true;
}
}
final String URL="jdbc:oracle:thin:@localhost:1521:orcl";
final String NAME="scott";
final String PASSWORD="tiger";
protected Connection con;
protected PreparedStatement pst;
protected Statement st;
protected ResultSet rs;
//连接数据库
public Connection getConnection(){
try {
Class.forName(DRIVER);
con=DriverManager.getConnection(URL, NAME, PASSWORD);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return con;
}
//关闭资源
public boolean closeNews(){
if(rs!=null)
try {
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
if(st!=null)
try {
st.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
if(pst!=null)
try {
pst.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
if(con!=null)
try {
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
return true;
}
}