Connect to a databse?
Hello!I wonder if it is possible, and how, to develop a stand alone application in Java that uses a database like Access or MySQL that can be downloaded and run on a client without that the user needs to create a odbc or install the database application?
With ASP I can do like this with a Access-file below so the ASP-app direct uses the file.
Set myDatabaseConnection = Server.CreateObject("ADODB.Connection")
databasePath = "../database/school.mdb"
connectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE="
connectionString = connectionString & server.mappath(databasePath) & ";"
myDatabaseConnection.open connectionString
So is it possible to do it the same in Java? I have only found these two ways with either jdbc:odbc or jdbc for MySql:
public MySQLTester()
{
try
{
Class.forName("org.gjt.mm.mysql.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/test?user=root&password=pass");
PreparedStatement preparedStatement = conn.prepareStatement("SELECT * FROM users");
ResultSet resultSet = preparedStatement.executeQuery();
while ( resultSet.next() )
{
System.out.println( resultSet.getString("id") );
System.out.println( resultSet.getString("name") );
System.out.println( resultSet.getString("password") );
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
public MySQLTester(String in)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("jdbc:odbc:test", "root", "pass");
PreparedStatement preparedStatement = conn.prepareStatement("SELECT * FROM users");
ResultSet resultSet = preparedStatement.executeQuery();
while ( resultSet.next() )
{
System.out.println( resultSet.getString("id") );
System.out.println( resultSet.getString("name") );
System.out.println( resultSet.getString("password") );
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
Best regards
Fredrik