Jamie Keeling
Jamie Keeling

Reputation: 9966

Java alternative to SQL Server 2008 - Compact

I am looking to get started with SQL development and as such have decided to implement an application in both Java and C# that makes use of an SQL based database, in particular it will be a desktop application that stores certain types of data on the user machine through the database.

After reading the answer posted here: C# local database I have decided to use SQL Server 2008 - Compact for the C# version and now I am looking for a suitable alternative for the Java version.

Following on from another post in Stack Overflow a user has recommended Apache Derby and H2.

Would they be a suitable option for the Java application? The SQL 2008 Compact boasts how it's well suited for desktop application development, I don't want to have to install a bundle of software just to persuade Java to use "localhost".

I hope i've provided enough information, feel free to ask for anything inparticular.

Thanks!

Upvotes: 0

Views: 443

Answers (3)

Axel
Axel

Reputation: 14159

Yes, go with derby. All you have to do is include the jar file into your project and start a database connection like this:

// load database driver
String user = ...;
String password = ...;
String driver = "org.apache.derby.jdbc.EmbeddedDriver";
Class.forName(driverName, false, this.getClass().getClassLoader());

// connect to database (replace DBName with your database name)
String url = "jdbc:derby:DBName;create=true;collation=TERRITORY_BASED"

Properties props = new Properties();
props.put("user", user);
props.put("password", password);

Connection connection = DriverManager.getConnection(url, props);

Then use the connection.

Upvotes: 0

Uhlen
Uhlen

Reputation: 1778

Why not use SQL Server 2008 also for the Java application? I recommend jTDS JDBC Driver.

Upvotes: 0

chmullig
chmullig

Reputation: 13406

Have you considered sqlite? You could easily use it for both Java and C#. It's nice and compact and pretty easy to work with. Here's a discussion of using it with Java.

Upvotes: 2

Related Questions