Hi Guys I have a Swing Application that is connected to an oracle database, I want it such that Once I type a Value into the JTextField, the other JTextfields on the JFrame are loaded with subsequent data from the database but I do not seem to achieve this. I have tried the Following code but it fetched nothing.
txtNo.addKeyListener(new KeyAdapter() {
public void keyTyped(KeyEvent ke) {
Connection conn = null;
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "Username", "Password");
Statement st = conn.createStatement();
String load = "Select * from Store_info_table where PART_NUMBER = '" + txtNo.getText() + "'";
ResultSet rs = st.executeQuery(load);
while(rs.next()){
txtName.setText(rs.getString("SPARE_DESC"));
}
}catch(Exception ae){
}
}
});
Best Answer
KeyListener
by aDocumentListener
catch
statements or you have no idea that something is going wrong. If you do not opt for decent error handling, at least log the stack trace (either by just printing it, or by using aLogger
).