Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 767009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T17:08:25+00:00 2026-05-14T17:08:25+00:00

I am writing a driver to act as a wrapper around two separate MySQL

  • 0

I am writing a driver to act as a wrapper around two separate MySQL connections (to distributed databases). Basically, the goal is to enable interaction with my driver for all applications instead of requiring the application to sort out which database holds the desired data.

Most of the code for this is in place, but I’m having a problem in that when I attempt to create connections via the MySQL Driver, the DriverManager is returning an instance of my driver instead of the MySQL Driver. I’d appreciate any tips on what could be causing this and what could be done to fix it!

Below is a few relevant snippets of code. I can provide more, but there’s a lot, so I’d need to know what else you want to see.

First, from MyDriver.java:

public MyDriver() throws SQLException
{
    DriverManager.registerDriver(this);
}

public Connection connect(String url, Properties info)
    throws SQLException
{
    try { return new MyConnection(info); }
    catch (Exception e) { return null; }
}

public boolean acceptsURL(String url) 
    throws SQLException
{
    if (url.contains("jdbc:jgb://"))
    { return true; }
    return false;
}

It is my understanding that this acceptsURL function will dictate whether or not the DriverManager deems my driver a suitable fit for a given URL. Hence it should only be passing connections from my driver if the URL contains “jdbc:jgb://” right?

Here’s code from MyConnection.java:

Connection c1 = null;
Connection c2 = null;

/** 
 *Constructors 
 */ 
public DDBSConnection (Properties info) 
    throws SQLException, Exception
{
    info.list(System.out); //included for testing
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    String url1 = "jdbc:mysql://server1.com/jgb";
    String url2 = "jdbc:mysql://server2.com/jgb";
    this.c1 = DriverManager.getConnection(
            url1, info.getProperty("username"), info.getProperty("password"));
    this.c2 = DriverManager.getConnection(
            url2, info.getProperty("username"), info.getProperty("password"));
}

And this tells me two things. First, the info.list() call confirms that the correct user and password are being sent. Second, because we enter an infinite loop, we see that the DriverManager is providing new instances of my connection as matches for the mysql URLs instead of the desired mysql driver/connection.

FWIW, I have separately tested implementations that go straight to the mysql driver using this exact syntax (al beit only one at a time), and was able to successfully interact with each database individually from a test application outside of my driver.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T17:08:26+00:00Added an answer on May 14, 2026 at 5:08 pm

    IMO, the main problem with this code is that it uses DriverManager. Avoid statics and stick with instances.

    The specific problem is the DriverManager.getConnection goes directly to attempting to connect rather than the acceptsURL that getDriver does. Therefore, you connect implementation should do the same check as the acceptsURL implementation (it may even be stricter and possibly fail at runtime).

    As a relatively minor point, the acceptsURL implementation is a little odd.

    if (url.contains("jdbc:jgb://"))
    { return true; }
    return false;
    

    contains should be startsWith. The little dance with if and returns does not help clarity. It can be written as:

    return url.startsWith("jdbc:jgb://");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a query to fetch results for all the values in a
I am learning on my own about writing an interpreter for a programming language,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.