How to connect NetBeans to MySQL database?

100,267

Solution 1

In the Services window you can right click on the Databases tab and select New Connection. New Connection

Select MySQL(Connector/J Driver) from the drop down list. The driver file should be listed in the window. If not, you can download the file, then click add and select it from your hard drive. Driver Information

Finally enter your database details such as servername, username and password and click finish. Database Details

Solution 2

If you meant you want to use IDE's GUI tool then

  • windows > services >database > driver
  • Get the driver jar
  • install the jar
  • right click on driver installed > connect using > and then provide the information

Or otherwise use JDBC

Solution 3

One way to connect to such databases is to use a JDBC (Java Database Connectivity) driver. You can find more about JDBC at the Oracle FAQ.

Solution 4

click on window and then select services

enter image description here

then click on databases and select new connection enter image description here

select driver which you want

enter image description here

then click finish

if you want to check the connection is successful or not

 try
    {
         con=DriverManager.getConnection("jdbc:mysql://localhost/student_result","root","");


JOptionPane.showMessageDialog(null,"connected with "+con.toString());


    }
    catch(Exception e)
    {
        JOptionPane.showMessageDialog(null,"not connect to server and message is"+e.getMessage());
    }
Share:
100,267
Amit
Author by

Amit

"Be a good person, but never try to prove it." #SOreadytohelp I am a professional programmer and a Certified Scrum Master (CSM) currently working as Full Stack Java Developer. Technical Skills Java (Core and Advaced), Spring Security, MicroServices, AWS, C, C++, Android, JSP, JavaScript, jQuery, AngularJS, HTML,JSP, PL/SQL, Hibernate etc. Areas of Interest Any kind of programming, R & D which pays enough money Java based Application Development i.e. Core Java, J2EE, J2ME, JNI, Web Development Software designing and Solution analysis for cloud plateforms. Have knowledge of AWS architecture but can work on Azure or Google cloud too if case 1 above is true :). Web Services and Microservices Development. Web application security and related frameworks and projects like prevention against OWASP's Top 10 vulnerabilities. Algorithm optimization, fine tuning, research & development.

Updated on August 21, 2020

Comments

  • Amit
    Amit over 3 years

    I have just installed NetBeans 7.0 and I am a newbie in NetBeans' world. can any one tell me how to connect my application to MySQl / Postgres ? I work on Windows XP.

    • Tim Sparg
      Tim Sparg almost 13 years
      Is your question about using the built in NetBeans SQL editor to access your database, or are you asking how to connect the program that you've written to a MySQL database?
  • Ravi Parekh
    Ravi Parekh almost 13 years
    @jigar u don't need to install jar. just select connetor/J dirver
  • jmj
    jmj almost 13 years
    @ravi I meant installation by that
  • Amit
    Amit almost 13 years
    @ravi and @Jigar : I have done all that... but still Class.forName() is throwing ClassNotFoundException. When I tried System.setProperty("jdbc.driver","driver info"); still it is not working.....
  • Ravi Parekh
    Ravi Parekh almost 13 years
    buddy u have to attache mysql.jar to run your project library. attache with naetbean is just like workbench,querybrowser, toad etc.
  • jmj
    jmj almost 13 years
    You need to provide driver jar into classpath