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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this