import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class DBO {
public static Connection conn=null;
public void dbo(){
//加载驱动
try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
}catch(ClassNotFoundException e){
System.out.println(e);
}
//建立连接
try{
conn=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=PetStore","olay","123456");
}catch(SQLException e){
System.out.println(e);
}finally{
try{
if(conn!=null){
conn.close();
}
}catch(SQLException e){
System.out.println(e);
//logger.error(e);需要加载logger包
}
}
}
}
import java.sql.DriverManager;
import java.sql.SQLException;
public class DBO {
public static Connection conn=null;
public void dbo(){
//加载驱动
try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
}catch(ClassNotFoundException e){
System.out.println(e);
}
//建立连接
try{
conn=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=PetStore","olay","123456");
}catch(SQLException e){
System.out.println(e);
}finally{
try{
if(conn!=null){
conn.close();
}
}catch(SQLException e){
System.out.println(e);
//logger.error(e);需要加载logger包
}
}
}
}