// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: ConnDB.java
package shopBeans;
import java.io.PrintStream;
import java.sql.*;
public class ConnDB
{
public Connection conn;
public Statement stmt;
public ResultSet rs;
private static String dbDriver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
private static String dbUrl = "jdbc:sqlserver://127.0.0.1:1433;DatabaseName=ShopSystem";
private static String dbUser = "sa";
private static String dbPwd = "";
public ConnDB()
{
conn = null;
stmt = null;
rs = null;
}
public static Connection getConnection()
{
Connection connection = null;
try
{
Class.forName(dbDriver);
connection = DriverManager.getConnection(dbUrl, dbUser, dbPwd);
}
catch (Exception exception)
{
exception.printStackTrace();
}
if (connection == null)
System.err.println("警告:数据库连接失败!");
return connection;
}
public ResultSet doQuery(String s)
{
try
{
conn = getConnection();
stmt = conn.createStatement(1004, 1007);
rs = stmt.executeQuery(s);
}
catch (SQLException sqlexception)
{
sqlexception.printStackTrace();
}
return rs;
}
public int doUpdate(String s)
{
int i = 0;
try
{
conn = getConnection();
stmt = conn.createStatement(1004, 1007);
i = stmt.executeUpdate(s);
}
catch (SQLException sqlexception)
{
i = 0;
}
return i;
}
public void closeConnection()
{
try
{
if (rs != null)
rs.close();
}
catch (Exception exception)
{
exception.printStackTrace();
}
try
{
if (stmt != null)
stmt.close();
}
catch (Exception exception1)
{
exception1.printStackTrace();
}
try
{
if (conn != null)
conn.close();
}
catch (Exception exception2)
{
exception2.printStackTrace();
}
}
}