Results 1 to 7 of 7
  1. #1
    Join Date
    Mar 2010
    Posts
    12
    Rep Power
    0

    Default Issue with MS Access database and a JAR

    Hi all,

    I'm working on a program that is basically just an interface for entering values into a Microsoft Access database. Every part of the program works properly in Eclipse, but when I export it to a runnable Jar file, it seems to get hung up on the location of the database.

    The program establishes the location of the database at startup by reading the contents of a text file located in the same directory as the program. A string is created, and is passed to constructor of the class which establishes the database connection. I know that it IS reading from the location file while in JAR form.

    Now, the rest of the program works in every way, but a connection to the database can never be made when in JAR form.

    Since I can't reproduce this in Eclipse, I ran the JAR from the command line and this is the error it produces:

    Java Code:
    java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
            at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
            at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
            at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(Unknown Source)
            at sun.jdbc.odbc.JdbcOdbcConnection.initialize(Unknown Source)
            at sun.jdbc.odbc.JdbcOdbcDriver.connect(Unknown Source)
            at java.sql.DriverManager.getConnection(Unknown Source)
            at java.sql.DriverManager.getConnection(Unknown Source)
            at Lamp.<init>(Lamp.java:26)
            at Main.main(Main.java:38)

    Anyone have any ideas? I think this all worked as a JAR on a Windows XP machine I was on, but not on my 7 machine. I might be wrong though.

    Thanks.

  2. #2
    Join Date
    Mar 2010
    Posts
    12
    Rep Power
    0

    Default

    If it helps, here is the class that makes the connection. Just can't imagine what it is about the JAR that's keeping this from working. :

    Java Code:
    public class Lamp 
    {
    	private static Statement s;
    	public static Connection con;
    	private static PreparedStatement updateComments;	
    	public static ResultSet rs;
    	static ResultSet hoursSet;
    	static ResultSet roomSet;
    	static ResultSet locationSet;
    	
    
    	public Lamp(String path)
    	{
    		try
    		{
    			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    
    			String filename = path;
    
    		    String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";  
    		    database+= filename.trim() + ";DriverID=22;READONLY=false}";
    		    
    		    con = DriverManager.getConnection(database ,"",""); 
    		    s = con.createStatement();   
    		}
    		catch(Exception e)
    		{
    			//JOptionPane.showMessageDialog(null,"Invalid database path." +
    												//"\n--Lamp()", "", JOptionPane.ERROR_MESSAGE);
    			e.printStackTrace();
    		}	
    	}

  3. #3
    Join Date
    Mar 2010
    Posts
    12
    Rep Power
    0

    Default

    One other update:

    It does work on my Windows XP machine, with one exception. It seems that the connection to the database does not close when on XP. At least this is what I assume is happening when I close the program and the little icon that says, "Microsoft Access Record-Locking Information" still remains. I have to open the database and close it again for the icon to disappear.

    Once again, these problems only manifest themselves when the program is run in JAR form.

  4. #4
    Join Date
    Mar 2010
    Posts
    12
    Rep Power
    0

    Default

    Problem fixed itself. Weird ... oh well.

  5. #5
    VallejosGM is offline Member
    Join Date
    Feb 2011
    Posts
    2
    Rep Power
    0

    Default The Jar does not work with MS Access

    Now I have the same problem. Can you tell me how you did it?
    Please help me. is very urgent.....

  6. #6
    Join Date
    Mar 2010
    Posts
    12
    Rep Power
    0

    Default

    I'm terribly sorry to tell you this, but like my previous response said, it just kind of fixed itself. It's been quite awhile since I was working with the program, so I don't remember everything that went on too clearly.

    My only guess was that it was a Java update that occurred, if that even makes any sense.

    If it helps you can PM me your email address, and I'll send the source code with some explanation your way. Maybe you'll find something that helps.

  7. #7
    VallejosGM is offline Member
    Join Date
    Feb 2011
    Posts
    2
    Rep Power
    0

Similar Threads

  1. java with access database
    By ashin in forum SWT / JFace
    Replies: 4
    Last Post: 07-12-2009, 06:04 PM
  2. Replies: 2
    Last Post: 02-11-2009, 05:43 AM
  3. SQL database issue
    By Dublin_kopite in forum New To Java
    Replies: 1
    Last Post: 02-04-2009, 06:34 PM
  4. Database access
    By Doctor Cactus in forum New To Java
    Replies: 1
    Last Post: 12-12-2008, 02:30 PM
  5. Replies: 1
    Last Post: 08-07-2007, 08:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •