
import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.*; public class NewJFramefin extends javax.swing.JFrame implements ActionListener {
public NewJFramefin()
{
initComponents();
add(jl1);
add(jf1);
jb1.setActionCommand("OK");
jb1.addActionListener(this);
add(jb1);
jb2.setActionCommand("CANCEL");
jb2.addActionListener(this);
add(jb2);
}
public void actionPerformed(ActionEvent e) { String find=jf1.getText(); String ev=e.getActionCommand(); String check; String str="jdbc:odbc:dsn1"; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection(str);
Statement s=con.createStatement();
s.execute("select * from Table1");
ResultSet res=s.getResultSet();
if(res!=null)
{
while(res.next())
{
check=res.getString(1);
System.out.println("STRING FROM DB:"+check + find);
if(ev.equalsIgnoreCase("OK") &&(find.equalsIgnoreCase(check)))
{
jf2.setText(res.getString(2));
add(jf2);
}
}
}
if(ev.equals("CANCEL"))
{
jf2.setText(" cancelled ");
add(jf2);
jf1.setText(" ");
add(jf1);
}
}
catch(Exception ew)
{
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.