7

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.

Amit
  • 13,134
  • 17
  • 77
  • 148
  • 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? – Tim Sparg May 22 '11 at 10:11

6 Answers6

11

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

Vincent Ramdhanie
  • 102,349
  • 23
  • 137
  • 192
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

jmj
  • 237,923
  • 42
  • 401
  • 438
  • @jigar u don't need to install jar. just select connetor/J dirver – Ravi Parekh May 21 '11 at 11:34
  • @ravi I meant installation by that – jmj May 21 '11 at 11:35
  • @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..... – Amit May 21 '11 at 11:55
  • buddy u have to attache mysql.jar to run your project library. attache with naetbean is just like workbench,querybrowser, toad etc. – Ravi Parekh May 21 '11 at 11:58
  • You need to provide driver jar into classpath – jmj May 21 '11 at 12:02
2

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.

Daniel
  • 855
  • 10
  • 21
1

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());
    }
Adiii
  • 54,482
  • 7
  • 145
  • 148
0

Follow the steps:-

1.Create a new application 2.In projects section of netbeans right click on libraries 3.Check the picture(i)Libraries java mysql connector Thus you successfully setup the connection with mysql.

Sudhir
  • 1
0

see mysql .jar for u project properties if u waant to run or for netbeans shown by @Vincent Ramdhanie enter image description here

Ravi Parekh
  • 5,253
  • 9
  • 46
  • 58