Advertisement
Guest User

fuck this shit.

a guest
Jun 7th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.11 KB | None | 0 0
  1. public void run() {
  2. try {
  3. // Create data input and output streams
  4. isFromClient = new DataInputStream(
  5. connectToClient.getInputStream());
  6. osToClient = new DataOutputStream(
  7. connectToClient.getOutputStream());
  8. // testsing connection
  9. String g = isFromClient.readUTF();
  10. System.out.println(g);
  11. // Continuously serve the client DOING ALL THE WORK
  12. Name123();
  13. } catch (IOException | SQLException ex) {
  14. System.err.println(ex);
  15. } catch (ClassNotFoundException ex) {
  16. Logger.getLogger(ServerGU.class.getName()).log(Level.SEVERE, null, ex);
  17. }
  18.  
  19. }
  20. }
  21.  
  22. public void Name123() throws SQLException, IOException, ClassNotFoundException {
  23. while (true) {
  24. boolean Done = false;
  25. while (!Done) {
  26. PreparedStatement ps;
  27. byte messageType = isFromClient.readByte();
  28.  
  29. switch (messageType) {
  30. case 1: {
  31. Connection con = DriverManager.getConnection(host, uName, uPass);
  32. Susername = isFromClient.readUTF();
  33. System.out.println("Username: " + Susername);
  34. Spassword = isFromClient.readUTF();
  35. System.out.println("Password: " + Spassword);
  36.  
  37. ps = con.prepareStatement("SELECT * FROM LOGIN WHERE username = ? AND password = ?");
  38. ps.setString(1, Susername);
  39. ps.setString(2, Spassword);
  40. ResultSet result = ps.executeQuery();
  41. if (result.next()) {
  42. System.out.println("Login Successfull!!!");
  43. String Pass = "Success";
  44. osToClient.writeUTF(Pass);
  45. } else {
  46. System.out.println("Wrong User OR Pass!!!");
  47. String Fail = "Failed";
  48. osToClient.writeUTF(Fail);
  49. }
  50. break;
  51. }
  52. case 2: {
  53. osToClient.writeUTF("first");
  54. osToClient.flush();
  55. // jTxtLog.setText(jTxtLog.getText() + new Date() + " first button" + '\n');
  56. Connection con = DriverManager.getConnection(host, uName, uPass);
  57. ps = con.prepareStatement("SELECT * FROM USERDATA where CUST_ID = 1");
  58. ResultSet result = ps.executeQuery();
  59.  
  60. if (result.next()) {
  61. String first = result.getString("FIRSTNAME");
  62. osToClient.writeUTF(first);
  63. String last = result.getString("LASTNAME");
  64. osToClient.writeUTF(last);
  65. String postcode = result.getString("POSTCODE");
  66. osToClient.writeUTF(postcode);
  67. String phone = result.getString("PHONENUMBER");
  68. osToClient.writeUTF(phone);
  69. String Email = result.getString("EMAILADDRESS");
  70. osToClient.writeUTF(Email);
  71.  
  72. } else {
  73. }
  74. break;
  75. }
  76. }
  77. }
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement