Results 1 to 2 of 2
  1. #1
    asai is offline Senior Member
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    115
    Rep Power
    0

    Default Database connection

    Hi,

    I have made a database connector class that connects to a MySQL database.
    Any suggestions on how I can alter this to connect to a Access database file instead?

    Code:
    Java Code:
    package MySQL;
    
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    
    public class Connector {
        
        private static String user_name = "root";
        private static String user_password = "";
        private static String url ="jdbc:mysql://10.10.160.6:3306/genealogy?zeroDateTimeBehavior=convertToNull";
        private static Connection connection = null;
        
        public static Connection getConnection(){
           
            try{
                Class.forName("com.mysql.jdbc.Driver");
            }
            catch (java.lang.ClassNotFoundException e){
                System.err.println("ClassNotFoundException: ");
                System.err.println(e.getMessage());
            }
            
            try{
                connection = DriverManager.getConnection(url, user_name, user_password);
            }
            catch(SQLException e){
                System.err.println("SQLException: " + e.getMessage());
            }
    
            return connection;
        }
        
    }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default Re: Database connection

    You'll need a different driver, which will mean a different url.
    You could look up the JDBC/ODBC bridge (which is old), or search for another suitable driver.
    Please do not ask for code as refusal often offends.

Similar Threads

  1. connection database
    By masoudy in forum Web Frameworks
    Replies: 3
    Last Post: 02-28-2013, 02:07 PM
  2. connection to database
    By manojkumarsahu in forum New To Java
    Replies: 1
    Last Post: 08-06-2010, 09:26 PM
  3. getting database connection
    By ravidasineni in forum AWT / Swing
    Replies: 0
    Last Post: 11-27-2009, 04:33 AM
  4. Database Connection
    By CompleteBeginner in forum New To Java
    Replies: 2
    Last Post: 05-24-2008, 02:30 PM
  5. Database connection
    By oaklander in forum New To Java
    Replies: 2
    Last Post: 11-12-2007, 11:11 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
  •