• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

I couldn't connect to JDBC and got error which I couldn't fix

 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
0


Can anyone please check my code and tell me where is the error ? I used MYSQL workbench for the database and I created database in my 'root' connection, however it comes with a password. I am just wondering if I need to mention my root connection password in the program by any chance. The error I got is not clear to me. I am expecting some response from expert  in this field who can genuinely figure out this bug.



the error I got:

Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500) at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481) at mysql.connector.java@5.1.38/com.mysql.jdbc.Util.handleNewInstance(Util.java:404) at mysql.connector.java@5.1.38/com.mysql.jdbc.Util.getInstance(Util.java:387) at mysql.connector.java@5.1.38/com.mysql.jdbc.SQLError.createSQLException(SQLError.java:917) at mysql.connector.java@5.1.38/com.mysql.jdbc.SQLError.createSQLException(SQLError.java:896) at mysql.connector.java@5.1.38/com.mysql.jdbc.SQLError.createSQLException(SQLError.java:885) at mysql.connector.java@5.1.38/com.mysql.jdbc.SQLError.createSQLException(SQLError.java:860) at mysql.connector.java@5.1.38/com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2332) at mysql.connector.java@5.1.38/com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2085) at mysql.connector.java@5.1.38/com.mysql.jdbc.ConnectionImpl.(ConnectionImpl.java:795) at mysql.connector.java@5.1.38/com.mysql.jdbc.JDBC4Connection.(JDBC4Connection.java:44) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500) at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481) at mysql.connector.java@5.1.38/com.mysql.jdbc.Util.handleNewInstance(Util.java:404) at mysql.connector.java@5.1.38/com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:400) at mysql.connector.java@5.1.38/com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:327) at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:677) at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:228) at zun.java.basics.practice.DemoClass.main(DemoClass.java:35) Caused by: java.lang.NullPointerException at mysql.connector.java@5.1.38/com.mysql.jdbc.ConnectionImpl.getServerCharset(ConnectionImpl.java:3005) at mysql.connector.java@5.1.38/com.mysql.jdbc.MysqlIO.sendConnectionAttributes(MysqlIO.java:1916) at mysql.connector.java@5.1.38/com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1845) at mysql.connector.java@5.1.38/com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1215) at mysql.connector.java@5.1.38/com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2255) at mysql.connector.java@5.1.38/com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2286) ... 14 more
 
Saloon Keeper
Posts: 9743
80
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
zun.java.basics.practice.DemoClass.main(DemoClass.java:35) Caused by: java.lang.NullPointerException at

Where is line 35?
 
Md Zuanyeed Kamal
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:zun.java.basics.practice.DemoClass.main(DemoClass.java:35) Caused by: java.lang.NullPointerException at

Where is line 35?



Accorging to Eclipse, line no 35 is :    Connection con = DriverManager.getConnection(url,uname,pass);
 
There is no beard big enough to make me comfortable enough with my masculinity to wear pink. Tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic