Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ClientTest{
- static PreparedStatement ps;
- static ResultSet rs;
- public static void main(String[] args)throws SQLException, ClassNotFoundException, IOException{
- Socket client = new Socket("127.0.0.1",33000);
- ObjectOutputStream out = new ObjectOutputStream(client.getOutputStream());
- ObjectInputStream in = new ObjectInputStream(client.getInputStream());
- Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
- Connection con = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=movie_max_database;integratedSecurity=true");
- String sql = "SELECT * FROM users";
- PreparedStatement ps = con.prepareStatement(sql);
- out.writeObject(ps);
- ResultSet rs = (ResultSet)in.readObject();
- while(rs.next()){
- System.out.print("user ID: " + rs.getString(1) + " userName: " + rs.getString(2) + " userPassword: "
- + rs.getString(3));
- }
- }
- public class ServerTest{
- public static void main(String[] args)throws SQLException,IOException,ClassNotFoundException{
- Connection con = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=movie_max_database;integratedSecurity=true");
- Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
- ServerSocket server = new ServerSocket(33000);
- Socket client = server.accept();
- ObjectInputStream in = new ObjectInputStream(client.getInputStream());
- ObjectOutputStream out = new ObjectOutputStream(client.getOutputStream());
- PreparedStatement ps =(PreparedStatement)in.readObject();
- ResultSet rs = ps.executeQuery();
- out.writeObject(rs);
- }
Add Comment
Please, Sign In to add comment