import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class BaseDAO {
private static String driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver";
private static String url="jdbc:sqlserver://localhost:1433;DatabaseName=zjlMovie";
private static String userName="sa";
private static String password="123456";
protected static Connection con=null;
protected PreparedStatement pstm=null;
protected ResultSet rs=null;
public void getConnection(){
try {
Class.forName(driverName);
con=DriverManager.getConnection(url, userName, password);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
public void closeAll(){
try {
if(rs!=null){
rs.close();
}
if(pstm!=null){
pstm.close();
}
if(con!=null){
con.close();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
java连接sql数据库代码
最新推荐文章于 2023-04-16 20:05:25 发布