In this tutorial you will be able to learn to search the data based on symbol number using java
Please watch the video because there are some task to be done beside code
Code to Search data in database using java
private void searchdataKeyReleased(java.awt.event.KeyEvent evt) {
// TODO add your handling code here:
try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String url="jdbc:sqlserver://localhost:1433;databaseName=testdb;user=sa;password=orchid";
Connection con = DriverManager.getConnection(url);
String sql = "Select * from users where sno =?";
PreparedStatement pst = con.prepareStatement(sql);
pst.setString(1, searchdata.getText());
ResultSet rs = pst.executeQuery();
if(rs.next()){
String setid = rs.getString("sno");
sno.setText(setid);
String setname = rs.getString("name");
name.setText(setname);
String setadd= rs.getString("address");
address.setText(setadd);
String sex = rs.getString("gender");
if(sex.equals("Male")){
male.setSelected(true);
}
else{
female.setSelected(true);
}
String knowledge = rs.getString("knowledge");
switch(knowledge){
case "Java ":
coreJava.setSelected(true);
python.setSelected(false);
break;
case "Python ":
python.setSelected(true);
coreJava.setSelected(false);
break;
default:
coreJava.setSelected(true);
python.setSelected(true);
break;
}
String subject1 = rs.getString("subject");
switch(subject1){
case "Computer Science":
subject.setSelectedIndex(0);
break;
case "Management":
subject.setSelectedIndex(1);
break;
case "Humanities":
subject.setSelectedIndex(2);
break;
case "Arts":
subject.setSelectedIndex(3);
break;
case "Education":
subject.setSelectedIndex(4);
break;
}
date_chooser.setDate(rs.getDate("date"));
byte[] img = rs.getBytes("images");
ImageIcon imageIcon = new ImageIcon(new ImageIcon(img).getImage().getScaledInstance(lbl_img.getWidth(),lbl_img.getHeight(),Image.SCALE_SMOOTH));
lbl_img.setIcon(imageIcon);
person_image = img;
}
}
catch(Exception e){
JOptionPane.showMessageDialog(null,e);
}
}
// TODO add your handling code here:
try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String url="jdbc:sqlserver://localhost:1433;databaseName=testdb;user=sa;password=orchid";
Connection con = DriverManager.getConnection(url);
String sql = "Select * from users where sno =?";
PreparedStatement pst = con.prepareStatement(sql);
pst.setString(1, searchdata.getText());
ResultSet rs = pst.executeQuery();
if(rs.next()){
String setid = rs.getString("sno");
sno.setText(setid);
String setname = rs.getString("name");
name.setText(setname);
String setadd= rs.getString("address");
address.setText(setadd);
String sex = rs.getString("gender");
if(sex.equals("Male")){
male.setSelected(true);
}
else{
female.setSelected(true);
}
String knowledge = rs.getString("knowledge");
switch(knowledge){
case "Java ":
coreJava.setSelected(true);
python.setSelected(false);
break;
case "Python ":
python.setSelected(true);
coreJava.setSelected(false);
break;
default:
coreJava.setSelected(true);
python.setSelected(true);
break;
}
String subject1 = rs.getString("subject");
switch(subject1){
case "Computer Science":
subject.setSelectedIndex(0);
break;
case "Management":
subject.setSelectedIndex(1);
break;
case "Humanities":
subject.setSelectedIndex(2);
break;
case "Arts":
subject.setSelectedIndex(3);
break;
case "Education":
subject.setSelectedIndex(4);
break;
}
date_chooser.setDate(rs.getDate("date"));
byte[] img = rs.getBytes("images");
ImageIcon imageIcon = new ImageIcon(new ImageIcon(img).getImage().getScaledInstance(lbl_img.getWidth(),lbl_img.getHeight(),Image.SCALE_SMOOTH));
lbl_img.setIcon(imageIcon);
person_image = img;
}
}
catch(Exception e){
JOptionPane.showMessageDialog(null,e);
}
}
Please don't forget To Like, Share and Subscribe my Youtube video and Channel.
Youtube Channel Subscription Click Here
This is the text that i speak in the video.
The text may not be correct as it is generated by the translator.
welcome previously I have created
a login form which meant the user provided data with database and this place whether
the login credentials are married or not and today I'll show you without the
text billion password field in the login form are empty or not so if user do
not provide login credentials and directly click on sign in button it matches a
database value and souls the message there is username and password not correct
so in today's tutorial I'll show you without typing any data you should display
message is username and password field is empty when user click on sign-in
button so for that let me place two level for displaying the message as
username and password finish empty so this is per username remove the text and
change your schedule name also so now double click on the Sign In button to
write the poor to check whether it is empty or not so you have to write before
the type try cache block so let me see what is the name of ourtake speed and
password field it is username and it is password so begin the coding if these
are main that is our XP name is chaim if it is empty and there is another pillow
the password field if we take for good the first time that's what means our
pasture field name but it takes Jean nd then what we have to do is we have to
display message a in the level is username is empty a password is empty so for
that okay one this we use an interval level name so this will display the
message is animate empty you know also so this will save only when both fill our
empty so if user name is only empty after that occurs for that
also so else if
let me copy this from here okay empty after what message I should display is
when user name is empty so display message in level on this condition I am that
user name is empty in password also
written earlier and secure for password I have to display this message level in
labor underscore password - password so if both fill are not empty and what I
have to do is that you take it to that did I miss value so LC statement will
run here so let me show you by running the code going to directly click on sign
button which will display messages user name is empty and password is empty so
when I provide it at this video then it will take now username a password is not
correct but the lip the message in the devil is still in the window so when user
types of data you should go away from so for that let me write the code so
please click on design character right click on the text field then after go to
events and go to Kien click on key released when the key is released the
message should be removed from the label so for that may work other school
indeed when the key is released the text should be the text field should be
empty the actors password also I can find the password field go to events and
go to key and click on released then after I done here leave all the school
that's what dot text so let me show you guy running it once username is empty a
password is nt let me provide username so the leave a message in the level is
remove and whenever there are some pass filter the message in the level is city
but again you may click on sign inverter so it is not correct so by this we can
perform the coding yourself
No comments:
Post a Comment