Vote count:
0
I have a problem here i am working upon combo box it works ok if i make a method of it and run it in the start of project but however when i use the action perform event it doesn't work. what i want to do is that when i select the drop down list button the data get fetch from sql. Can anyone help me?
package data_fetching_from_sql;
import java.sql.*;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
public class Practice_for_sql extends javax.swing.JFrame {
public Practice_for_sql() {
initComponents();
clear();
}
DefaultTableModel model;
private void clear() {
model=(DefaultTableModel) tbl_shw.getModel();
int count=tbl_shw.getRowCount();
for(int i=count-1; i>=0; i--) {
model.removeRow(i);
}
}
private void cmb_emply_namActionPerformed(java.awt.event.ActionEvent evt) {
try {
clear();
String e_id=txt_emp_id.getText();
model = (DefaultTableModel) tbl_shw.getModel();
Connection cn=
DriverManager.getConnection("jdbc:http://sqlserverlocalhost:1433;Database=db_Car_Reservation;
user=sa; password=123;");
Statement st=cn.createStatement();
ResultSet rs=st.executeQuery("select * from employee where eid like '"+e_id+"%'");
while(rs.next()) {
model.addRow(new Object[{rs.getString("sno"),rs.getString("eid"),rs.getString("name"),
rs.getString("mob"),rs.getString
("email"),rs.getString("emp_auth"),rs.getString("emp_status")});
}
}
catch(SQLException ex) {
JOptionPane.showMessageDialog(this, ex);
}
}
asked 43 secs ago
how to get data from sql using combo box in net beans while selecting the dropdown button in it
Aucun commentaire:
Enregistrer un commentaire