
i want to convert JTextField data into string object. I used getText method and stored in ojbect but i want to compare with a database element but it shows some error.

Hi Friend,
Try the following code:
import java.sql.*;
import java.awt.*;
import java.util.*;
import javax.swing.*;
import java.awt.event.*;
class Check{
JLabel l,lab1,lab2;
ArrayList list;
JTextField text,text1,text2;
JButton button;
Check(){
l=new JLabel("Enter Name: ");
text=new JTextField(20);
JFrame frame=new JFrame();
frame.setLayout(null);
button=new JButton("Submit");
l.setBounds(10,10,100,20);
text.setBounds(120,10,100,20);
button.setBounds(120,40,90,20);
frame.add(l);
frame.add(text);
frame.add(button);
frame.setVisible(true);
frame.setSize(300,100);
list=new ArrayList();
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String value=text.getText();
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:student");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from data ");
String name="";
while(rs.next()){
name=rs.getString("name");
list.add(name);
}
if(list.contains(value)){
System.out.println("Matches with database");
}
else{
System.out.println("Does not match");
}
}
catch(Exception ex){}
}
});
}
public static void main(String[] args)
{
new Check();
}
}
Thanks
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.