Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void run() {
- try {
- // Create data input and output streams
- isFromClient = new DataInputStream(
- connectToClient.getInputStream());
- osToClient = new DataOutputStream(
- connectToClient.getOutputStream());
- // testsing connection
- String g = isFromClient.readUTF();
- System.out.println(g);
- // Continuously serve the client DOING ALL THE WORK
- Name123();
- } catch (IOException | SQLException ex) {
- System.err.println(ex);
- } catch (ClassNotFoundException ex) {
- Logger.getLogger(ServerGU.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }
- public void Name123() throws SQLException, IOException, ClassNotFoundException {
- while (true) {
- boolean Done = false;
- while (!Done) {
- PreparedStatement ps;
- byte messageType = isFromClient.readByte();
- switch (messageType) {
- case 1: {
- Connection con = DriverManager.getConnection(host, uName, uPass);
- Susername = isFromClient.readUTF();
- System.out.println("Username: " + Susername);
- Spassword = isFromClient.readUTF();
- System.out.println("Password: " + Spassword);
- ps = con.prepareStatement("SELECT * FROM LOGIN WHERE username = ? AND password = ?");
- ps.setString(1, Susername);
- ps.setString(2, Spassword);
- ResultSet result = ps.executeQuery();
- if (result.next()) {
- System.out.println("Login Successfull!!!");
- String Pass = "Success";
- osToClient.writeUTF(Pass);
- } else {
- System.out.println("Wrong User OR Pass!!!");
- String Fail = "Failed";
- osToClient.writeUTF(Fail);
- }
- break;
- }
- case 2: {
- osToClient.writeUTF("first");
- osToClient.flush();
- // jTxtLog.setText(jTxtLog.getText() + new Date() + " first button" + '\n');
- Connection con = DriverManager.getConnection(host, uName, uPass);
- ps = con.prepareStatement("SELECT * FROM USERDATA where CUST_ID = 1");
- ResultSet result = ps.executeQuery();
- if (result.next()) {
- String first = result.getString("FIRSTNAME");
- osToClient.writeUTF(first);
- String last = result.getString("LASTNAME");
- osToClient.writeUTF(last);
- String postcode = result.getString("POSTCODE");
- osToClient.writeUTF(postcode);
- String phone = result.getString("PHONENUMBER");
- osToClient.writeUTF(phone);
- String Email = result.getString("EMAILADDRESS");
- osToClient.writeUTF(Email);
- } else {
- }
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement