package jxjpd;
import Java.io.*;
import Java.SQL
.*;
import com.microsoft.jdbc.sqlserver.*;
public class DBconn{
String dbDriver="com.microsoft.jdbc.sqlserver.SQLServerDriver";
Connection conn;
Statement stmt;
ResultSet rs;
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pd";
public DBconn()
{
try
{
Class.forName(dbDriver);
}catch(Exception e){System.out.println("Driver is error!");}
}
public Connection getConn()
{
try
{
if(conn==null)
conn=DriverManager.getConnection(url,"sa","");
else
{
conn.close();
conn=DriverManager.getConnection(url,"sa","");
}
}catch(Exception e){System.out.println("Connection is error!");}
return conn;
}
public ResultSet getRs(String sql)
{
try
{
this.getConn();
stmt=conn.createStatement();
rs=stmt.executeQuery(sql);
}catch(Exception e){System.out.println("resultSet is error!");}
return rs;
}
public void insertStu(String insertStr)
{
try
{
this.getConn();
stmt=conn.createStatement();
stmt.executeUpdate(insertStr);
}catch(Exception e){}
}
public void closed()
{
try
{
if(rs!=null){rs.close();}
if(stmt!=null){stmt.close();}
if(conn!=null){conn.close();}
}catch(Exception e){System.out.println("close is error!");}
}
}