Guest User

Untitled

a guest
Feb 12th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. txtNo = new JTextField();
  2. {
  3. try {
  4. Class.forName("com.mysql.jdbc.Driver");
  5. String srcurl1 = "jdbc:mysql://localhost:3306/DB_name";
  6. Connection con = DriverManager.getConnection(srcurl1,"root","paswrd");
  7. Statement stmt1 = con.createStatement();
  8. ResultSet rs1 = stmt1.executeQuery("select No from bank where No='"+txtNo.getText()+"' ");
  9.  
  10. int ch =rs1.getInt("No");
  11. int ch4= Integer.parseInt(txtNo.getText());
  12.  
  13. if(ch==ch4) // input 58 == 58
  14. System.out.println("already exits");
  15. }
  16. catch(Exception e)
  17. {
  18. System.out.println("Exception:"+e);
  19. }
  20. }
  21.  
  22. while(rs1.next())
  23. {
  24. int ch = rs1.getInt("No");
  25. // ...
  26. }
  27.  
  28. if (rs1.next()) {
  29. int ch =rs1.getInt("No");
  30. ...
  31. }
  32.  
  33. Select 1 from bank where No = [your_supplied_value]
  34.  
  35. txtNo = new JTextField();
  36. {
  37. try {
  38. String compareText = txtNo.getText().trim();
  39.  
  40. if(compareText.length() > 0){
  41. Class.forName("com.mysql.jdbc.Driver");
  42. String srcurl1 = "jdbc:mysql://localhost:3306/DB_name";
  43. Connection con = DriverManager.getConnection(srcurl1,"root","paswrd");
  44. Statement stmt1 = con.createStatement();
  45. ResultSet rs1 = stmt1.executeQuery("select 1 from bank where No='"+txtNo.getText()+"' ");
  46.  
  47. boolean isPresent = rs1.next();
  48.  
  49. if(isPresent){
  50. System.out.println("Already exists!!");
  51. }
  52. }
  53. }
  54. catch(Exception e)
  55. {
  56. System.out.println("Exception:"+e);
  57. }
  58. }
Add Comment
Please, Sign In to add comment