This week's book giveaway is in the XML and Related Technologies forum.
We're giving away four copies of Java XML & JSON and have Jeff Friesen on-line!
See this thread for details.
Win a copy of Java XML & JSON this week in the XML and Related Technologies forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

JDBC Password URL problem  RSS feed

 
Bartender
Posts: 1634
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have a JDBC MySQL password with lots of special characters, including "%". Now, MySQL works fine using this password from Navicat, WordPress, Drupal, etc., but when I try to connect via a JDBC connection string using this password, I get:

Cannot load connection class because of underlying exception: com.mysql.cj.exceptions.WrongArgumentException: URLDecoder: Incomplete trailing escape (%) pattern

What I've tried:

1. I tried escaping the password in the JDBC connection string like this

final String DATABASE_URL =
               "jdbc:mysql://localhost:3306/lookup?useSSL=false&" +
                       "serverTimezone=America/New_York&user=root&password=\"password_here\"&autoReconnect=true";

2. Different JDBC driver.

3. URLEncoding the password itself. In this case, I get the message that the connection tried three times and gave up -- meaning my URL Encoding wasn't accepted.

---

Would appreciate suggestions how to get around this password issue. I can't change the password itself since there are so many CMS/other clients that actively use the MySQL database.

Thanks very much in advance,

-- mike
 
Bartender
Posts: 1088
36
IBM DB2 Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It may silly to ask you this: have you tried using



It should do treat special characters for you.


 
Mike London
Bartender
Posts: 1634
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Claude Moore wrote:It may silly to ask you this: have you tried using



It should do treat special characters for you.




That's a good idea. I went ahead and instead created a less-powerful user, with no root access, and only SQL access for the database.

Thanks for your reply.

-- mike
 
Claude Moore
Bartender
Posts: 1088
36
IBM DB2 Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried this:



And it worked without problems. MySql  Server release is 5.6
 
Mike London
Bartender
Posts: 1634
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Claude Moore wrote:I tried this:



And it worked without problems. MySql  Server release is 5.6



That's cool. Thanks.

In any case, I can't get the JDBC logic to work without the Class.forName to explicitly load the driver.

Even with code like below, if I run it, I'll get a "no suitable driver found"

Thanks,

-- mike
 
Claude Moore
Bartender
Posts: 1088
36
IBM DB2 Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Mike London wrote:
In any case, I can't get the JDBC logic to work without the Class.forName to explicitly load the driver.
Even with code like below, if I run it, I'll get a "no suitable driver found"



It may be a symptom that required *.jar are not in your application classpath. From JDBC 4.0, if I'm not wrong, JDBC drivers are automatically registered when present in classpath; I don't understant what you mean sayng that you need to explicitly load MySql JDBC driver with Class.forName. I would guess you need also to call Driver.registerDriver to make it available to your application.
 
Bartender
Posts: 20307
110
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Claude Moore wrote:From JDBC 4.0, if I'm not wrong, JDBC drivers are automatically registered when present in classpath;



You are not wrong. There's a special line in the Manifest file in the JDBC driver jar that is detected to register the driver class. Class.forName is extremely obsolete at this point. It's harmless, but unnecessary.

The registerDriver method is supposed to be called by the driver itself when this condition exists, not part of user-written code.

 
Mike London
Bartender
Posts: 1634
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Holloway wrote:

Claude Moore wrote:From JDBC 4.0, if I'm not wrong, JDBC drivers are automatically registered when present in classpath;



You are not wrong. There's a special line in the Manifest file in the JDBC driver jar that is detected to register the driver class. Class.forName is extremely obsolete at this point. It's harmless, but unnecessary.

The registerDriver method is supposed to be called by the driver itself when this condition exists, not part of user-written code.



Hi Tim,

I am loading the JDBC driver in the Maven POM.XML.

Yet, without the explicit Class.forName.... I get a unregistered driver exception.

-- mike
 
Claude Moore
Bartender
Posts: 1088
36
IBM DB2 Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which version of the driver are you using ? Maybe, it's an outdated one, so that autoregistering of the driver doesn't take place. Are you sure you are loading the correct driver class ?
I tried with:



it worked, bu I also got a warning:

"Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary."
 
Mike London
Bartender
Posts: 1634
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Claude Moore wrote:Which version of the driver are you using ? Maybe, it's an outdated one, so that autoregistering of the driver doesn't take place. Are you sure you are loading the correct driver class ?
I tried with:



it worked, bu I also got a warning:

"Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary."



I'm using the new driver.

I'll try creating a separate test class shortly and will report back.

Thanks,

-- mike
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!