【发布时间】:2014-02-08 22:28:35
【问题描述】:
我一直在尝试以多种不同的方式连接到我的 SQL 服务器。我正在为 Microsoft SQL Server 2012 使用 jdbc4 驱动程序。我已经在构建路径中输入了它。当我尝试将我的代码作为 android 应用程序运行时,我的困惑就出现了。运行代码时出现以下错误。
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());
}
}
}
【问题讨论】:
标签: java android sql sql-server-2012