Win a copy of Machine Learning for Business: Using Amazon SageMaker and JupyterE this week in the Jython/Python forum
or Object Design Style Guide in the Object-Oriented programming 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
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

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

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • 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: 6771
64
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • 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: 57
  • Mark post as helpful
  • send pies
  • 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);
 
Grow a forest with seedballs and this tiny ad:
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!