Advertisement
Guest User

Untitled

a guest
Nov 3rd, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. import java.sql.*;
  2. import java.util.Scanner;
  3.  
  4. public class takeInput
  5. {
  6. public static void main (String arg[])
  7. {
  8. String url = "jdbc:mysql://localhost:3306/demo";
  9. String user = "bihim";
  10. String pass = "shimu";
  11. //int count = 0;
  12.  
  13. try
  14. {
  15. //Connection to database
  16.  
  17. Connection myConn = DriverManager.getConnection(url,user,pass);
  18.  
  19. //Create Statement
  20.  
  21. Statement mySt = myConn.createStatement();
  22.  
  23. //Execute sql query
  24.  
  25. //String sql = "insert into emp" + "(userid, pass)" + "values (?,?)";
  26.  
  27. //mySt.executeUpdate(sql);
  28.  
  29. //mySt = myConn.prepareStatement("insert into emp" + "(userid, pass)" + "values('?' , '?')");
  30.  
  31. //Setting the parameters
  32. Scanner scan = new Scanner(System.in);
  33. // String uzer = scan.nextLine();
  34. // String puss = scan.nextLine();
  35.  
  36. // PreparedStatement pst = null;
  37. // pst = myConn.prepareStatement(sql);
  38. // pst.setString(1, uzer);
  39. // pst.setString(2, puss);
  40. // pst.execute();
  41.  
  42.  
  43. //System.out.println("Insert Completed");
  44. String takeInput = scan.nextLine();
  45. //String takePass = scan.nextLine();
  46. ResultSet myRs = mySt.executeQuery("select userid from emp where userid='"+takeInput+"'");
  47.  
  48.  
  49.  
  50. while (myRs.next())
  51. {
  52.  
  53.  
  54. if (takeInput.equals(myRs.getString("userid")))
  55. {
  56. System.out.println("You did it fam");
  57.  
  58. }
  59. }
  60. }
  61.  
  62. catch (Exception exc)
  63. {
  64.  
  65. }
  66. }
  67.  
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement