Click here to Skip to main content
15,889,826 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
hello.
I need help in creating my application , i create a database and connect it to my application my database contain manger table having a id, name,....etc of fields when i enter any id in textfield it must compare the value o textfield with database values how can i do this.
thnx in advance .
Posted
Updated 11-Sep-11 22:39pm
v2
Comments
Pravin Patil, Mumbai 11-Sep-11 1:47am    
Do you want to avoid putting duplicate values in database..?
hamzah1 11-Sep-11 2:21am    
sure yes no duplicated value will be exist.

- Make ID the Key value of DB
- Fetch Dataset with the desired ID
- compare to whatever

Or do you need a SQL-Command for retrieving duplicates? I'll add a SQL-Tag anyway.
 
Share this answer
 
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:MyDSN","sa","sa");PreparedStatement st=con.prepareStatement("select id from manger");
ResultSet rs=st.ExecuteQuery();
String ID1=JTextField1.getText();
String ID2=rs.getString("id");
if(ID1.equals(ID2))
{
  //ID matched...
  // Do whatever you want...
}
else
{
  //ID do not match...
  // Throw error message...
}

/*
Note:--- 
1) import java.sql.*;
2) import javax.sql.*;
3) MyDSN is the name of the Data Source.
4) sa is the id for SQL server Authentication and sa is the password.
5) JTextField1 is the ID of Text Box on your form.
*/
 
Share this answer
 
Comments
hamzah1 12-Sep-11 9:45am    
thanks aloot
ShwetaSaxena 13-Sep-11 3:34am    
You r most welcome for the questions....:)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900