有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

javajdbc程序从数据库中提取

所以我已经完全编程了一个JDBC文件,它从MySQL数据库中提取数据。现在,我想用我的文件创建一个“2008SQLServerR2”。对于我的JDBC程序,我目前将其设置为:

public class JDBCPullFromTable {
 //JDBC driver name and database URL
 static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";  
 static final String DB_URL = "jdbc:mysql://localhost:3306/MyDB";
 static final String USER = "root";
 static final String PASS = "pw";
.....
...
..
.
  Class.forName("com.mysql.jdbc.Driver");

 //Open a connection
 //System.out.println("Connecting to a selected database...");
 conn = DriverManager.getConnection(DB_URL, USER, PASS);

从现在开始,我如何让它连接到2008 SQL SERVER R2?使用Microsoft SQL Server Management Studio访问此数据库。我假设我会下载JDBC驱动程序,但是用户名和密码呢?我会使用登录演播室时使用的那个吗?谢谢

目前我所拥有的

 static final String JDBC_DRIVER = "**NOWIDEAWHATTHISIS**";  
 static final String DB_URL = "jdbc:sqlserver://localhost:1433/NEdatabasename";

 //Database credentials
 static final String USER = "neuser";
 static final String PASS = "nepass";

共 (2) 个答案

  1. # 1 楼答案

    我相信您正在寻找的是:

    com.microsoft.sqlserver.jdbc.SQLServerDriver
    

    要连接到SQL server,可以使用

         Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
         Connection conn = DriverManager.getConnection(DB_URL,
                  USER, PASS);
    

    然后用连接做你想做的事

  2. # 2 楼答案

    首先,您需要下载SQLServeur2008的jdbc驱动程序。 其次,用户名和密码与用于连接数据库的用户名和密码相同。 所以它将是这样的:

    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
    static final String DB_URL = "jdbc:sqlserver://localhost:1433/NEdatabasename";
    
    //Database credentials
    static final String USER = "neuser";//Username of the db
    static final String PASS = "nepass";//password of the db
    Connection conn = DriverManager.getConnection(DB_URL,USER, PASS);