• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

Create a MySQL Connection

 
Ranch Hand
Posts: 2114
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using Java 1.7
I have added mysql-connector-java-5.1.24-bin.jar to my project.

This is my connection string:



I get this message:

java.sql.SQLException: Access denied for user 'sqlread@smar-birst1.corp.zodiac.com'@'10.195.143.154' (using password: YES)

However, these credentials exist in the database.
 
Ranch Foreman
Posts: 121
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let's get a few basics right here:

1) mysql-connector 5.1 is a JDBC 4.x compliant driver which uses the ServiceLoader API - no need for it to be added explicitly - you just have to have it in the classpath at startup
2) user credentials - have a look at docs: getConnection(String, String, String) takes a jdbc-url, a username and a password; "sqlread@smar-birst1.corp.zodiac.com" isn't a username, but "sqlread" is; anything after the @ is a hostname - so this line means: the user sqlread is allowed to connect from the remote host smar-birst1.corp.zodiac.com
3) I guess you have set up some local DNS - as the hostname used in the url is just that, a plain hostname, not a FQDN or localhost - this is error prone and can be a potential security risk - either use FQDN or IPs - but don't use just hostnames that rely on correct local dns resolving - in worst case it can even be abused to extract data from your intranet to some external localtion
4) if you allow remote connection on the database server (already a bad idea) don't rely on remote host identification - as this also relies on DNS (reverse dns in this case) - set up proper TLS tunnels secured by good and valid X.509 certs - even Let's Encrypt certs do the trick for that usecase
5) don'T use java1.7 anymore unless there's some really important reason you absolutely have to - upgrade to at least the latest LTS java11
 
I'm gonna teach you a lesson! Start by looking at this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic