tags:

views:

117

answers:

3

I need to make an application in Java , which needs to use SQL database . I wil provide the users with the database file , but that won't run because to setup the database connection we first need to add a User DSN in Windows . Is there a way to add it( User DSN ) automatically when the applcation installs ?

+1  A: 

Gaurav, the canonical way to do these things is by using JDBC. They provide a uniform, simple interface.

Charlie Martin
+1  A: 

I wil provide the users with the database file , but that won't run because to setup the database connection we first need to add a User DSN in Windows.

I don't think that'll work unless there's a MySQL server listening on port 3306.

User DSN in Windows is not the way to go. (Nothing "platform independent" about that.)

The Java way to connect to any database is JDBC. Here's an example showing how to do it with MySQL. You'll need the Connector-J JAR in your CLASSPATH, of course.

duffymo
A: 

If you're using Java and JDBC, your database connection has a URL.
It takes the basic form jdbc:mysql://hostname:port/database

They're also going to need to know the JDBC driver classname for the database you're installing. So, you'll need to prompt them for those two things.

Your users are going to need to know those things about their data bases to use your app.

You could, as you suggest, use a JDBC / ODBC connector and set up an ODBC Dsname. But if you want good performance, you're probably better off using native JDBC. You can include the class library for the driver in your application class path and install it yourself.

The driver is called Connector / J for mySQL, and it works well.

Ollie Jones