我一直在尝试以很多不同的方式连接到我的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());
}
}
}