Jump to content
Sign in to follow this  

Mysql connectivity to java(Netbeans)

Recommended Posts

So i have created a basic program on retrieving a table from mysql(named "book") onto a table in java (name "buklau").

The name of the database is "12sci".

I cant get it to work! Pls help me out. Thank you.


Heres the code on the retrieve button:


DefaultTableModel model= (DefaultTableModel)buklau.getModel();
Statement stmt = con.createStatement();
String query="SELECT * FROM book";
ResultSet rs=stmt.executeQuery(query);
String nm=rs.getString("name");
String ph=rs.getString("phone");
String ct=rs.getString("city");
model.addRow(new Object[]{nm,ph,ct});
catch(Exception e){
JOptionPane.showMessageDialog(null, "e");
heres the pic of the msql database

Share this post

Link to post
Share on other sites

Do you have the J/Connector installed? Can you successfully establish a connection to the database?

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Create New...