Java NetBeans Tutorial: Connecting to a MySQL Database with Java, JDBC and NetBeans




Download Java Source Code: http://www.luv2code.com/?p=992 In this video you will learn how to connect to MySQL with Java and NetBeans. Please subscribe …

Original source


26 responses to “Java NetBeans Tutorial: Connecting to a MySQL Database with Java, JDBC and NetBeans”

  1. thanks for ur knowledge,
    i got this red messages after i run the program
    ((com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Access denied for user ''@'localhost' to database 'demo'))? therefore i cant connect to my server!!
    any idea why bro?

  2. PLEASE HELP! I received this error:

    com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

    The last packet sent successfully to the server was 0 milliseconds ago. The driver has not
    received any packets from the server.

    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
    at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:989)
    at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:341)
    at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2251)
    at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2284)
    at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2083)
    at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:806)
    at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
    at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:410)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:328)
    at java.sql.DriverManager.getConnection(DriverManager.java:664)
    at java.sql.DriverManager.getConnection(DriverManager.java:247)
    at esd.JDBC.main(JDBC.java:31)
    Caused by: java.net.ConnectException: Connection refused: connect
    at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:211)
    at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:300)
    … 15 more

  3. Hey Sean,

    I have an issue with my own program I made for my school,
    it uses  Java DB and JPC. Whenever I try to code to make it get data to my normal login application and my questionnaire(for tests in schools) it has an error saying this:

    Exception in thread "main" java.lang.RuntimeException: Uncompilable source code – Erroneous sym type: com.pluralsight.DBManager.setVisible
     at com.pluralsight.DBManager.main(DBManager.java:60)
    Java Result: 1
    BUILD SUCCESSFUL (total time: 1 second)

    I know it sounds stupid trying to show the DB to the application but I am terrible at  SQL and did a bit of NetBeans coding to it store the name's in the program.
    Please help 🙁

  4. Thanks, you'r way to explain is very simple and to the point. It's easy to follow and I don't fill I'm wasting my time. You'r code works great! I use you'r example code but with "try with resources" so you don't need code to close the data base, Java will do it for u. Thanks again.

Leave a Reply