Guest User

Untitled

a guest
Sep 27th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. public class ClientTest{
  2. static PreparedStatement ps;
  3. static ResultSet rs;
  4. public static void main(String[] args)throws SQLException, ClassNotFoundException, IOException{
  5. Socket client = new Socket("127.0.0.1",33000);
  6. ObjectOutputStream out = new ObjectOutputStream(client.getOutputStream());
  7. ObjectInputStream in = new ObjectInputStream(client.getInputStream());
  8.  
  9. Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
  10. Connection con = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=movie_max_database;integratedSecurity=true");
  11. String sql = "SELECT * FROM users";
  12. PreparedStatement ps = con.prepareStatement(sql);
  13. out.writeObject(ps);
  14. ResultSet rs = (ResultSet)in.readObject();
  15.  
  16. while(rs.next()){
  17. System.out.print("user ID: " + rs.getString(1) + " userName: " + rs.getString(2) + " userPassword: "
  18. + rs.getString(3));
  19. }
  20. }
  21.  
  22. public class ServerTest{
  23.  
  24. public static void main(String[] args)throws SQLException,IOException,ClassNotFoundException{
  25. Connection con = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=movie_max_database;integratedSecurity=true");
  26. Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
  27.  
  28. ServerSocket server = new ServerSocket(33000);
  29. Socket client = server.accept();
  30.  
  31. ObjectInputStream in = new ObjectInputStream(client.getInputStream());
  32. ObjectOutputStream out = new ObjectOutputStream(client.getOutputStream());
  33.  
  34. PreparedStatement ps =(PreparedStatement)in.readObject();
  35. ResultSet rs = ps.executeQuery();
  36. out.writeObject(rs);
  37. }
Add Comment
Please, Sign In to add comment