I am building an android app in eclipse and I cant connect to my MS Access database.I am using a code I found online, it was using JTBS but I didn't want my database to be on a server so I changed it to ODBC.(I am a beginner so keep in mind my mistake might be very basic or stupid) here is my code:
import java.sql.*;
public final class Database
{
public Connection connectionObj;
private Statement statement;
public static Database dataBase;
ResultSet res ;
Database()
{
String url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=C:/Users/barw1_000/Desktop/Projects/SwinApp;";
String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
String userName = "";
String password = "";
try
{
Class.forName(driver).newInstance();
this.connectionObj = (Connection)DriverManager.getConnection(url,userName,password);
}
catch (Exception sqle)
{
sqle.printStackTrace();
}
}
/**
*
* @return MysqlConnect Database connection object
*/
public static synchronized Database getDbCon()
{
if ( dataBase == null )
{
dataBase = new Database();
}
return dataBase;
}
/**
*
* @param query String The query to be executed
* @return a ResultSet object containing the results or null if not available
* @throws SQLException
*/
public ResultSet query(String query) throws SQLException
{
statement = dataBase.connectionObj.createStatement();
res = statement.executeQuery(query);
return res;
}
/**
* @desc Method to insert data to a table
* @param insertQuery String The Insert query
* @return boolean
* @throws SQLException
*/
public int insert(String insertQuery) throws SQLException
{
statement = dataBase.connectionObj.createStatement();
int result = statement.executeUpdate(insertQuery);
return result;
}
}
The error shown is:
Invalid layout of java.lang.String at value
#
# A fatal error has been detected by the Java Runtime Environment:
#
# Internal Error (javaClasses.cpp:126), pid=7136, tid=4712
# fatal error: Invalid layout of preloaded class
#
# JRE version: (8.0_25-b18) (build )
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.25-b02 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\barw1_000\Desktop\Projects\SwinApp\SwimApp\hs_err_pid7136.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.sun.com/bugreport/crash.jsp
#
I also don't know how to use this database with the app so if you can give me any information about it, that would be really great.