belajar post coding for netbeans
Membuat database
database: project123table : userinfo
atribut :
pumpid | integer (11) |
date | date |
pressure | integer (11) |
temperature | integer (11) |
volumeFlow | integer (11) |
rotationalSpeed | integer (11) |
javaconnect.java
import java.sql.*;
import javax.swing.*;
public class javaconnect {
Connection conn = null;
public static Connection ConnecrDb(){
try{
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/project123","root","");
//JOptionPane.showMessageDialog(null, "Koneksi Sukses ...!!");
return conn;
}catch(Exception e){
JOptionPane.showMessageDialog(null, e);
return null;
}
}
}
import javax.swing.*;
public class javaconnect {
Connection conn = null;
public static Connection ConnecrDb(){
try{
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/project123","root","");
//JOptionPane.showMessageDialog(null, "Koneksi Sukses ...!!");
return conn;
}catch(Exception e){
JOptionPane.showMessageDialog(null, e);
return null;
}
}
}
Form Userinfo_frame.java
Userinfo_frame.java
import java.sql.*;
import javax.swing.*;
import net.proteanit.sql.DbUtils;
public class Userinfo_frame extends javax.swing.JFrame {
Connection conn = null;
ResultSet rs = null;
PreparedStatement pst = null;
public Userinfo_frame() {
initComponents();
conn = javaconnect.ConnecrDb();
Update_table();
}
public void close(){
WindowEvent winClosingEvent = new WindowEvent(this, WindowEvent.WINDOW_CLOSING);
Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(winClosingEvent);
}
public void Update_table(){
try{
String sql = "select * from userinfo";
pst = conn.prepareStatement(sql);
rs = pst.executeQuery();
Table_User.setModel(DbUtils.resultSetToTableModel(rs));
}catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}finally{
try{
rs.close();
pst.close();
}catch(Exception e){
}
}
}
import javax.swing.*;
import net.proteanit.sql.DbUtils;
public class Userinfo_frame extends javax.swing.JFrame {
Connection conn = null;
ResultSet rs = null;
PreparedStatement pst = null;
public Userinfo_frame() {
initComponents();
conn = javaconnect.ConnecrDb();
Update_table();
}
public void close(){
WindowEvent winClosingEvent = new WindowEvent(this, WindowEvent.WINDOW_CLOSING);
Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(winClosingEvent);
}
public void Update_table(){
try{
String sql = "select * from userinfo";
pst = conn.prepareStatement(sql);
rs = pst.executeQuery();
Table_User.setModel(DbUtils.resultSetToTableModel(rs));
}catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}finally{
try{
rs.close();
pst.close();
}catch(Exception e){
}
}
}
disini saya menggunakan library MYSQL JDBC Driver itu ada langsung di paket javanya
dan kita menambahkan jar rs2xml download http://sitinurhanifa4.blogspot.co.id/2017/01/download-free-rs2xml.html
Hasilnya
yang belum jelas boleh bertanya di komentar, insyaAllah dijawab...!
Komentar
Posting Komentar