debakun Posted September 12, 2016 Share Posted September 12, 2016 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 Link to comment Share on other sites More sharing options...
debakun Posted September 12, 2016 Author Share Posted September 12, 2016 So is there sumthing wrong with netbeans or mysql? Link to comment Share on other sites More sharing options...
davej Posted September 12, 2016 Share Posted September 12, 2016 Do you have the J/Connector installed? Can you successfully establish a connection to the database? Link to comment Share on other sites More sharing options...
debakun Posted September 13, 2016 Author Share Posted September 13, 2016 Oh thank you!! Was using an outdated version of the j/connector we used at school.Thank you for your help.:-) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now