1

I have been trying to connect to my SQL server many different way. I am using jdbc4 driver for Microsoft SQL Server 2012. I have input it in the build path. My confusion comes when I try to run my code as an android application. I get the following error when the code is ran.

 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

If you would like to submit a bug report, please visit: 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());
    }

}

}

0

2 Answers 2

1

Your class name driver does not seem correct, change to:

driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver"

and make sure the driver jar is in the classpath.

Sign up to request clarification or add additional context in comments.

Comments

0

Don't know for sure if the driver is incorrect as isah says, but your error seems pretty much like that one

So I think you are forgetting one step: Run As -> Android Application

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.