Cara Otomatis Reload Web Setelah Input Data
Posted on by admin
- Cara Otomatis Reload Web Setelah Input Data Center
- Auto Refresh Table Without Refreshing Page Php Mysql
- Auto Refresh Content After Changes In Database Java
Operations in Excel, such as combine sheets quickly, merge cells without losing data, paste to only visible cells, count cells by color and so on. 300+ powerful. Tutorial ini kita akan membuat script untuk mengisi field di form secara otomatis atau dengan kata lain Menampilkan data berdasarkan id ke textbox secara otomatis maksudnya jika kita menginputkan data yang menjadi id / primary, maka data yang lain akan masuk secara otomatis, Untuk menampilkan data di textbox sesuai data yang ada didatabase yang dengan bahasa lainnya mungkin menampilkan isi.
autoNumber.java
/* |
*@ author resa cr |
* This program can modify and share |
*/ |
importjava.awt.EventQueue; |
importjavax.swing.JFrame; |
importjavax.swing.JPanel; |
importjavax.swing.border.EmptyBorder; |
importjavax.swing.JLabel; |
importjavax.swing.JOptionPane; |
importjavax.swing.JTextField; |
importjavax.swing.JTextArea; |
importjavax.swing.JButton; |
importjava.awt.event.ActionListener; |
importjava.awt.event.ActionEvent; |
importjava.sql.Connection; |
importjava.sql.PreparedStatement; |
importjava.sql.ResultSet; |
importjava.sql.Statement; |
importjavax.swing.ImageIcon; |
publicclassautoNumberextendsJFrame |
{ |
privateJPanel contentPane; |
privateJTextField txtId; |
privateJTextField txtNama; |
privateJTextArea textArea; |
/** |
* Create the frame. |
*/ |
publicautoNumber() |
{ |
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
setBounds(100, 100, 499, 334); |
contentPane =newJPanel(); |
contentPane.setBorder(newEmptyBorder(5, 5, 5, 5)); |
setContentPane(contentPane); |
contentPane.setLayout(null); |
JLabel lblNoid =newJLabel('No.ID : '); |
lblNoid.setBounds(12, 12, 70, 15); |
contentPane.add(lblNoid); |
txtId =newJTextField(); |
txtId.setBounds(100, 10, 114, 19); |
txtId.setEditable(false); |
contentPane.add(txtId); |
txtId.setColumns(10); |
JLabel lblNama =newJLabel('Nama : '); |
lblNama.setBounds(12, 56, 70, 15); |
contentPane.add(lblNama); |
txtNama =newJTextField(); |
txtNama.setBounds(100, 54, 309, 19); |
contentPane.add(txtNama); |
txtNama.setColumns(10); |
JLabel lblAlamat =newJLabel('Alamat : '); |
lblAlamat.setBounds(12, 96, 70, 15); |
contentPane.add(lblAlamat); |
textArea =newJTextArea(); |
textArea.setLineWrap(true); |
textArea.setBounds(100, 96, 264, 86); |
contentPane.add(textArea); |
JButton btnSimpan =newJButton('Simpan'); |
btnSimpan.setIcon(newImageIcon('/home/resa/Aplikasi Java/MembuatAutoNumber/src/Gambar/Simpan.png')); |
btnSimpan.addActionListener(newActionListener() |
{ |
publicvoid actionPerformed(ActionEvent act) |
{ |
try |
{ |
Connection konek =Koneksi.getKoneksi(); |
String query ='INSERT INTO Data VALUES(?,?,?)'; |
PreparedStatement prepare = konek.prepareStatement(query); |
prepare.setInt(1,Integer.parseInt(txtId.getText())); |
prepare.setString(2,txtNama.getText()); |
prepare.setString(3,textArea.getText()); |
prepare.executeUpdate(); |
JOptionPane.showMessageDialog(null,'Data berhasil disimpan','Pesan',JOptionPane.INFORMATION_MESSAGE); |
prepare.close(); |
} |
catch(Exception ex) |
{ |
JOptionPane.showMessageDialog(null,'Data gagal disimpan','Pesan',JOptionPane.ERROR_MESSAGE); |
System.out.println(ex); |
} |
finally |
{ |
autonumber(); //Menampilkan autonumber setelah data disimpan |
} |
} |
}); |
btnSimpan.setBounds(100, 229, 135, 36); |
contentPane.add(btnSimpan); |
JButton btnKeluar =newJButton('Keluar'); |
btnKeluar.setIcon(newImageIcon('/home/resa/Aplikasi Java/MembuatAutoNumber/src/Gambar/Keluar.png')); |
btnKeluar.addActionListener(newActionListener() |
{ |
publicvoid actionPerformed(ActionEvent act) |
{ |
System.exit(0); |
} |
}); |
btnKeluar.setBounds(247, 229, 135, 36); |
contentPane.add(btnKeluar); |
JLabel lblAutoGenerate =newJLabel('* Auto Generate Number'); |
lblAutoGenerate.setBounds(222, 12, 187, 15); |
contentPane.add(lblAutoGenerate); |
JLabel lblBackground =newJLabel(''); |
lblBackground.setIcon(newImageIcon('/home/resa/Aplikasi Java/MembuatAutoNumber/src/Gambar/background.png')); |
lblBackground.setBounds(0, 0, 495, 307); |
contentPane.add(lblBackground); |
autonumber(); //menampilkan autonumber |
} //Akhir Konstruktor |
publicvoidautonumber() |
{ |
try |
{ |
Connection konek =Koneksi.getKoneksi(); |
Statement state = konek.createStatement(); |
String query ='SELECT MAX(id) FROM Data'; //Mendapatkan nilai id terakhir |
ResultSet rs = state.executeQuery(query); |
if(rs.next()) |
{ |
int a = rs.getInt(1); |
txtId.setText(Integer.toString(a+1)); //Nilai input yang terakhir ditambahkan 1 |
} |
rs.close(); |
state.close(); |
} |
catch(Exception ex) |
{ |
System.out.println(ex); |
} |
finally |
{ |
txtNama.setText(''); |
textArea.setText(''); |
txtNama.requestFocus(); |
} |
} |
/** |
* Launch the application. |
*/ |
publicstaticvoidmain(String[] args) |
{ |
EventQueue.invokeLater(newRunnable() |
{ |
publicvoid run() { |
try |
{ |
autoNumber frame =new autoNumber(); |
frame.setVisible(true); |
} |
catch (Exception e) |
{ |
e.printStackTrace(); |
} |
} |
}); |
} |
} |
Cara Otomatis Reload Web Setelah Input Data Center
Koneksi.java
/* |
*@ author resa cr |
* This program can modify and share |
*/ |
importjava.sql.DriverManager; |
importjava.sql.Connection; |
publicclassKoneksi |
{ |
privatestaticConnection koneksi; |
publicstaticConnectiongetKoneksi() |
{ |
if(koneksi null) |
{ |
try |
{ |
String url ='jdbc:mysql://localhost/autonumber'; |
String user ='root'; |
String password ='root'; |
DriverManager.registerDriver(newcom.mysql.jdbc.Driver()); |
koneksi =DriverManager.getConnection(url,user,password); |
} |
catch(Exception ex) |
{ |
System.out.println(ex); |
} |
} |
return koneksi; |
} |
} |
Auto Refresh Table Without Refreshing Page Php Mysql
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment
Auto Refresh Content After Changes In Database Java
Hy , i have a problem.
I read the other threads but i didn`t understood and none of the codes worked.
I`m using VB 2005 and SQL Server 2005.
I have 1 form with a DataGridView bounded to the table Produse and 3 texboxes and 1 Save button.
In the save button i`ve putted the code :
The code works fine , it saves the data i`ve enterd in the textboxes , but in order to view the changes in the table i need to restart my application to see the changes.
Any ideea how to refresh the DataGridView ?
Please help.
Comments are closed.