Sign in to follow this  
Followers 0
debakun

Mysql connectivity to java(Netbeans)

4 posts in this topic

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();
try{
Class.forName("java.sql.Driver");
Statement stmt = con.createStatement();
String query="SELECT * FROM book";
ResultSet rs=stmt.executeQuery(query);
while(rs.next()){
String nm=rs.getString("name");
String ph=rs.getString("phone");
String ct=rs.getString("city");
model.addRow(new Object[]{nm,ph,ct});
}
rs.close();
stmt.close();
con.close();
}
catch(Exception e){
JOptionPane.showMessageDialog(null, "e");
}
heres the pic of the msql database
Untitled.png

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  
Followers 0