我正在使用SQL Server 2008作爲數據庫。並使用JDBC,我正在訪問數據庫作爲下。SQL服務器中的Class.forName
public class DBConn {
public static void main(String[] args) throws ClassNotFoundException, SQLException{
Connection con =null;
//Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection("jdbc:sqlserver://BG4WS0552:1433;databaseName=DynamicsAx2009",
"TESTUSER", "[email protected]");
Statement stmt = con.createStatement();
String query = "SELECT * FROM custtable";
DatabaseMetaData dmd = con.getMetaData();
ResultSet rs = dmd.getColumns ("DynamicsAx2009", "%", "custtable", null) ;
ResultSetMetaData rsmd = rs.getMetaData();
int i = 1;
while (rs.next()) {
System.out.print(i++ + " COLUMN_NAME is " + rs.getString("COLUMN_NAME"));
System.out.print(" TYPE:" + rs.getString("TYPE_NAME"));
System.out.println(" DATA_TYPE is " + rs.getString("DATA_TYPE"));
}
}}
看到上面的代碼,我已評論指出的Class.forName( 「com.microsoft.sqlserver.jdbc.SQLServerDriver」)。即使我的程序運行良好。請讓我知道它如何在沒有註冊驅動程序的情況下工作。