• sqlserver > JAVA连接SQLSERVER的例子
  • JAVA连接SQLSERVER的例子

    免费下载 下载该文档 文档格式:DOC   更新时间:2007-05-02   下载次数:0   点击次数:2
    文档基本属性
    文档语言:Simplified Chinese
    文档格式:doc
    文档作者:Lenovo User
    关键词:
    主题:
    备注:
    点击这里显示更多文档属性
    JAVA连接SQLSERVER的例子
    set classpath=.;C:\MyJava\JDBCPack\MSSQL\msbase.jar;C:\MyJava\JDBCPack\MSSQL\msutil.jar;C:\MyJava\JDBCPack\MSSQL\mssqlserver.jar
    */
    import java.sql.*;
    import java.io.*;
    import java.*;
    public class Connect{
    private java.sql.Connectioncon = null;
    private final String url = "jdbc:microsoft:sqlserver://";
    private final String serverName= "GONGTAO";
    private final String portNumber = "1433";
    private final String databaseName= "pubs";
    private final String userName = "sa";
    private final String password = "";
    // Informs the driver to use server a side-cursor,
    // which permits more than one active statement
    // on a connection.
    private final String selectMethod = "cursor";

    // Constructor
    public Connect(){}

    private String getConnectionUrl(){
    return url+serverName+":"+portNumber+";databaseName="+databaseName+";selectMethod="+selectMethod+";";
    }

    private java.sql.Connection getConnection(){
    try{
    Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
    con = java.sql.DriverManager.getConnection(getConnectionUrl(),userName,password);
    if(con!=null) System.out.println("Connection Successful!");
    }catch(Exception e){
    e.printStackTrace();
    System.out.println("Error Trace in getConnection() : " + e.getMessage());
    }
    return con;
    }
    /*

    Display the driver properties, database details
    */

    下一页

  • 下载地址 (推荐使用迅雷下载地址,速度快,支持断点续传)
  • 免费下载 DOC格式下载
  • 您可能感兴趣的
  • sqlserver2008下载  sqlserver数据库  sqlserver2000安装  sqlserver2005企业版  sqlserver2000个人版  sqlserver2000xp下载  sqlserver2005下载  sqlserver2008jdbc  sqlserver2000