.Jar to connect to .mdb (Access Database) problem...

publicstatic Connection getConnection()throws Exception{

Connection con;

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

// set this to a MS Access DB you have on your machine

String url ="jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb)};DBQ=data\\db.mdb";

// now we can get the connection from the DriverManager

con = (Connection) DriverManager.getConnection( url ,"","");

return con;

}

This code connects to the database. It works fine in ECLIPSE.

When i compile the jar and run it freezes when connection to database but it does put a lock on the database so the path is definately correct.

Files are located here:

//data/db.mdb

//application.jar

And when the jar is run it wont work as described above.

Any help greatly appreciated.

[1183 byte] By [SiForstera] at [2007-11-27 11:11:42]
# 1

>the database so the path is definately correct

are you sure ?

Use an absolute path to access your mdb files.

See this http://64.18.163.122/rgagnon/javadetails/java-0107.html

java_2006a at 2007-7-29 13:49:55 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

Yes, checked it with full path and result is the same.

java.version=1.4.2_03 just incase that helps...

Works fine in Eclipse as I say, only happens when I make it a jar.

Also, its not possible to access a database inside a jar is it?

SiForstera at 2007-7-29 13:49:55 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3

>Also, its not possible to access a database inside a jar is it?

No, it's possible.

could you post your manifest content plz ?

BTW, does your application need third party libraries (.jars) ?

java_2006a at 2007-7-29 13:49:55 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4

Application uses thirdparty jars for form layout and jgoodies.

Nothing to interfere with the connection.

The jar loads fine, then when i click the "do query" style button the nothing happens.

Manifest-Version: 1.0

Main-Class: src.Main

SiForstera at 2007-7-29 13:49:55 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 5

add this to your manifest file:

Class-Path: jar1-name jar2-name

where jar1-name and jar2-name (and others) are the third party jars.

More info => See:

http://java.sun.com/docs/books/tutorial/deployment/jar/downman.html

>Main-Class: src.Main

BTW, are you sure the Main class is included in a package called src?

java_2006a at 2007-7-29 13:49:55 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 6

> add this to your manifest file:

> Class-Path: jar1-name jar2-name

> where jar1-name and jar2-name (and others) are the

> third party jars.

Made no difference....

> >Main-Class: src.Main

> BTW, are you sure the Main class is

> included in a package called src?

Yes, and as I say, it loads fine. Everything works apart from a screen where it reads a row off the database.

That works fine in eclipse but wont work as a jar. The database locks however, showing that something (the jar) has connected to it.

SiForstera at 2007-7-29 13:49:55 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 7

use this code:

public static Connection getConnection() {

try{

Connection con;

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

// set this to a MS Access DB you have on your machine

String url = "jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb)};DBQ=data\\db.mdb";

// now we can get the connection from the DriverManager

con = (Connection) DriverManager.getConnection( url ,"","");

return con;

}catch(Exception e){

e.printStackTrace();

}

}

then post the eventual error message plz

java_2006a at 2007-7-29 13:49:55 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 8

Where do errors from jar's print to?

It doesnt error in Eclipse.

SiForstera at 2007-7-29 13:49:55 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 9

open MS-DOS then go where your executable jar is located then type:

java -jar YOUR_JAR_NAME.jar

java_2006a at 2007-7-29 13:49:55 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 10

HA - I never knew you did that... that makes so much sense. Thanks

Looks more solvable now like!

Cheers!

java.lang.NoClassDefFoundError: org/mlc/swing/layout/LayoutConstraintsManager

at src.Job.viewJob(Job.java:70)

at src.JobViewer.addContent(JobViewer.java:108)

at src.JobViewer.setup(JobViewer.java:53)

at src.JobViewer.<init>(JobViewer.java:42)

at src.MainMenu$1.actionPerformed(MainMenu.java:72)

at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)

at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Unknow

n Source)

at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)

at javax.swing.DefaultButtonModel.setPressed(Unknown Source)

at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Sour

ce)

at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)

at java.awt.Component.processMouseEvent(Unknown Source)

at java.awt.Component.processEvent(Unknown Source)

at java.awt.Container.processEvent(Unknown Source)

at java.awt.Component.dispatchEventImpl(Unknown Source)

at java.awt.Container.dispatchEventImpl(Unknown Source)

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)

at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)

at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)

at java.awt.Container.dispatchEventImpl(Unknown Source)

at java.awt.Window.dispatchEventImpl(Unknown Source)

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.EventQueue.dispatchEvent(Unknown Source)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.run(Unknown Source)

SiForstera at 2007-7-29 13:49:55 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 11

Cant seem to fix this bug like.

SiForstera at 2007-7-29 13:49:55 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 12

> Cant seem to fix this bug like.

1. This has nothing to do with jdbc.

2. You are missing a class, so that means something is missing in your jar, probably another jar.

jschella at 2007-7-29 13:49:55 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 13

> 2. You are missing a class, so that means something

> is missing in your jar, probably another jar.

Probably the manifest in the jar file doesn't correctly refer to that other jar file.

DrClapa at 2007-7-29 13:49:55 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...