Jar file not connecting to database
Hi all,
I had created a jar of swing application. when i execute the jar file from command prompt it runs OK.
Now i had create a installer of that swing application using third party tool. After installing, when i execute the application from program menu. application runs but it is not connecting to database.
If i run same installed application which is located in Program Files from command prompt. it also run OK.
why this happening.....
could you people help me out. It's very urgent...
Thanks in advance
[554 byte] By [
Bhagwana] at [2007-11-27 0:25:36]

# 1
I had the same problem before, I got an exception when the program starts performing some database actions.
To solve this, jar your files normailly, and in your code, when you specify database file name put it absolute, (i.e. without path), for example:
String databaseFile = "myDB.mdb";
then jar your program classes and locate your database file in the same location of the generated jar file. this scenario should work..
good luck
jotnarta
Message was edited by:
jotnarta
# 2
Thankx for your reply....
I had tried your solution but it is not working.....
Giving the same problem...
below is the code
public SQLiteConnection()
{
try {
// The SQLite (3.3.8) Database File
String fileName = "Finance.db";
// Driver to Use
Class.forName("org.sqlite.JDBC");
// Create Connection Object to SQLite Database
conn = DriverManager.getConnection("jdbc:sqlite:"+fileName);
// Create a Statement object for the database connection
stmt = conn.createStatement();
}
catch (Exception e) {
System.out.println("Error :"+e);
}
}
# 3
My guess... Right click on the icon the installer created in the menu, select properties.What does it say for 'Start In'I bet that is blank and/or not set to the directory your application is installed in.
# 4
Are you importing your driver at the top of your code? I use a MySQL in a Login class in a Jar application I created, and in the top of my code I have:
import com.mysql.jdbc.Driver;
I also distribute the driver along with my Jar file in a separate Lib folder. I don't know if that is necessary though. Whatever the case, it might be because your application is simply not finding the driver file.
# 5
Thanx for your reply,
I had placed all the required driver files in the same directory where is my application jar is present.
I had also place the line import org.sqlite.JDBC;
in my program.
Till application not connecting to the my SQLIte database.
Same application is run from the Command prompt....
Waiting for you kind reply.
Thanks in advance...
# 6
Thankx all people.Problem get solved. Actually that was my mistake, i forget to include class path in manifest file.
# 7
Hi, I am not sure about this result. You first try with 4th driver (i.e) using odbc connection. I hope it will work., coz its working for me... the coding will be like this Hope u will get it also. Bye, Rajkumar
# 8
coding....
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:dsn");
Statement st = con.createStatement();
String sql="select * from table";
ResultSet rs= st.executeQuery(sql);
while (rs.next()) {
// do your logic here
}