我一直在嘗試以很多不同的方式連接到我的SQL服務器。我正在爲Microsoft SQL Server 2012使用jdbc4驅動程序。我已經在構建路徑中輸入它。當我嘗試將我的代碼作爲Android應用程序運行時,我的困惑就來臨了。代碼運行時出現以下錯誤。到SQL Server的Java連接(錯誤)
Invalid layout of java.lang.String at value
A fatal error has been detected by the Java Runtime Environment:
Internal Error (javaClasses.cpp:136), pid=5992, tid=5208
fatal error: Invalid layout of preloaded class
JRE version: (7.0_51-b13) (build)
Java VM: Java HotSpot(TM) 64-Bit Server VM (24.51-b03 mixed mode windows-amd64 compressed oops)
Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
An error report file with more information is saved as:
C:\Users\LiL_Blevs11\Google Drive\CPET 490\Database\workspace\MedRecords\hs_err_pid5992.log
如果您想提交錯誤報告,請訪問: http://bugreport.sun.com/bugreport/crash.jsp
package com.seniordesign.medrecords;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import android.app.Activity;
public class MainActivity extends Activity {
public static void main(String[] args) {
Connection connection = null;
try {
// Load the NetDirect JDBC driver
String driverName = "com.microsoft.sqlserver.jdbc";
Class.forName(driverName);
// Create a connection to the database
String computer = "LIL_BLEVS-PC";
String serverName = "SQLEXPRESS";
String serverPort = "1433";
String database = computer + "\"" + serverName + ":" + serverPort;
String url = "jdbc:sqlserver://" + database;
String username = "username";
String password = "password";
connection = DriverManager.getConnection(url, username, password);
System.out.println("Successfully Connected to the database!");
} catch (ClassNotFoundException e) {
System.out.println("Could not find the database driver "
+ e.getMessage());
} catch (SQLException e) {
System.out.println("Could not connect to the database "
+ e.getMessage());
}
}
}