??????????????????Sqlserver?????????????Sqlserver?????????????????????????????????д?????????
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class sqlServer {
ResultSet rs=null;
//????????????????
String url="jdbc:sqlserver://localhost:1433;databaseName=Pet";
String     DriverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver";
//???????
String userName="sa";
//?????????
String password="123";
//????????????????
public Connection getConnection(){
//????????
try {
Class.forName(DriverClassName);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Connection con =null;
//??????????
try {
con =DriverManager.getConnection(url??userName??password);
System.out.println("?????????????");
//?????????
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return con;
}
//======??????????=======
public  void ShiFang(ResultSet rs?? Statement st??Connection con){
//????????????????????? ?????????
try {
if(rs!=null){
rs.close();
}if(st!=null){
st.close();
}if(con!=null){
con.close();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}