日期:2014-05-20  浏览次数:20709 次

在JBuilder2005中怎样连接数据库SQL2000
在JBuilder2005中怎样连接数据库SQL2000,需要如何设置?本人需详细步骤,请各位高手帮忙,谢谢!急急急!

------解决方案--------------------
Java code

import java.sql.*;

/**
 * 获得连接
 */

public class DBHelper {
    public DBHelper() {
    }

    public static Connection getConn() {
        Connection conn = null;
        try {
            Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
            conn = DriverManager.getConnection(
                    "jdbc:sqlserver://localhost:1433;databaseName=pubs", "sa",
                    "");
        } catch (SQLException ex) {
            System.out.println(ex.getMessage());
        } catch (ClassNotFoundException ex) {
            System.out.println(ex.getMessage());
        }
        return conn;
    }
    /**
     * 关闭连接
     * @param conn Connection
     */
    public static void clostConn(Connection conn) {
        if (conn != null) {
            try {
                conn.close();
                conn = null;
            } catch (SQLException ex) {
                ex.printStackTrace();
            }
        }
    }
}