daily pastebin goal
61%
SHARE
TWEET

Untitled

a guest Jun 5th, 2017 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package Proyecto;
  2.  
  3.    import java.net.*;
  4.    import java.io.*;
  5.    import java.sql.*;
  6.  
  7.     class servidor {
  8.  
  9.       static Connection canal = null;
  10.       static Statement instruccion=null;
  11.       static ResultSet rs;
  12.  
  13.       static String tt1;
  14.       static String tt2;
  15.       static String libro ;
  16.       static String s;
  17.       static String respuesta;
  18.  
  19.       static int Contador=0;
  20.        public static void main (String[] args) throws IOException, SQLException {
  21.  
  22.  
  23.          System.out.println("Servidor funcionando");
  24.          ServerSocket servSocket = new ServerSocket(9001);
  25.          while (true) {
  26.             Socket socket = servSocket.accept();
  27.             OutputStream salida = socket.getOutputStream();
  28.             DataOutputStream salidaDatos = new DataOutputStream(salida);
  29.             InputStream entrada = socket.getInputStream();
  30.             DataInputStream entradaDatos = new DataInputStream(entrada);
  31.  
  32.          System.out.println("atendiendo a cliente");
  33.  
  34.             tt1=entradaDatos.readUTF();
  35.             System.out.println("*"+tt1+"*");
  36.             try {
  37.  
  38.             Class.forName("com.mysql.jdbc.Driver");
  39.             canal = DriverManager.getConnection("jdbc:mysql://localhost:3306/movil", "root", "silvana");
  40.            // String tt1= "TALA";
  41.             instruccion = canal.createStatement();
  42.             //System.out.println("antes del selec");
  43.             ResultSet rs = instruccion.executeQuery(
  44.                     "select * from libro where libro.libro= '"+tt1+"'");
  45.             // System.out.println("despues del selec");
  46.             while (rs.next()) {
  47.                 tt2=(rs.getString(1) + " " + rs.getString(2)
  48.                         + " " + rs.getString(3)+"   "+rs.getString(4));
  49.                 System.out.println(""+tt2);
  50.                
  51.             }
  52.  
  53.         salidaDatos.writeUTF(tt2);
  54.  
  55.         } catch (Exception e) {
  56.             e.printStackTrace();
  57.         }
  58.          
  59.      }
  60.    }
  61. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top