学生宿舍管理系统旨在使用计算机管理系统简化学校传统的管理模式
源代码在线查看: dbconnect.java
/*
*DBConnect.java
*AdminControl.java
*author:liuhaijing
*/
package mydesign;
import java.sql.*;
import java.io.*;
public class DBConnect
{
Connection conn=null;
Statement stmt=null;
ResultSet r=null;
String url="jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=MyDesign";
String username="sa";
String password="933713";
String driver="com.microsoft.jdbc.sqlserver.SQLServerDriver";
public DBConnect()
{
try
{
Class.forName(driver);
conn=DriverManager.getConnection(url,username,password);
stmt=conn.createStatement();
}
catch(Exception ex)
{
System.out.print("连接数据库发生错误:"+ex.getMessage());
}
}
//ResultSet Query
public ResultSet executeQuery(String sql)
{
try
{
r=stmt.executeQuery(sql);
}
catch(Exception ex)
{
System.out.print("查询发生错误:"+ex.getMessage());
}
return r;
}
//executeUpdate
public void executeUpdate(String sql)
{
try
{
stmt.executeUpdate(sql);
}
catch(Exception ex)
{
System.out.print("执行SQL发生错误:"+ex.getMessage());
}
}
//close the conn
public void close()
{
try
{
if(r!=null) r.close();
if(stmt!=null) stmt.close();
if(conn!=null) conn.close();
}
catch(Exception ex)
{
System.out.print("closeconn Error:"+ex.getMessage());
}
}
}