Results 1 to 2 of 2
  1. #1
    habiler is offline Member
    Join Date
    Sep 2016
    Rep Power

    Default problem connection Access DB


    My code below has no error by compling or debuggig but I don't have any connection with mydB.
    What's matter with my code.


    Java Code:
    import java.util.*;
    import java.sql.*;
    public class PersonDAO
          // arraylist used to store PersonInfo objects
    	private ArrayList personsList;
    	private Connection conn;
         // constructor 
    	public PersonDAO()
    		personsList = new ArrayList();
          // method used to establish connection with DB
    	public void initConn()
    			// load driver
                      // establishing connection
                      Connection conn = DriverManager.getConnection("jdbc:ucanaccess://c:/Users\\hab\\Desktop\\Decisionsjava1.accdb;memory=false");
    		catch(Exception e)

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Rep Power

    Default Re: problem connection Access DB

    Java Code:
    Connection conn = DriverManager.getConnection("jdbc:ucanaccess://c:/Users\\hab\\Desktop\\Decisionsjava1.accdb;memory=false");
    That is a different conn variable to the one declared as an attribute of the class.
    The above conn is local only to the method initConn.

    You probably meant to do:
    Java Code:
    conn = DriverManager.getConnection("jdbc:ucanaccess://c:/Users\\hab\\Desktop\\Decisionsjava1.accdb;memory=false");
    which would be referring to the attribute.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. connection to MS access database
    By bigjo in forum New To Java
    Replies: 3
    Last Post: 11-06-2012, 05:42 PM
  2. MS Access to Java Connection Problems
    By EminOz in forum JDBC
    Replies: 0
    Last Post: 12-22-2011, 01:51 PM
  3. Access connection error
    By jasonwucinski in forum JDBC
    Replies: 15
    Last Post: 04-21-2011, 10:00 AM
  4. Accessing MS Access using DSN less connection
    By Java Tip in forum Java Tip
    Replies: 1
    Last Post: 03-31-2009, 06:25 PM
  5. connection between ms access and jcreator
    By tiger100plus in forum New To Java
    Replies: 0
    Last Post: 11-24-2008, 04:34 PM

Posting Permissions

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