title: Socket Programming using mysql in java
body: <p>I have created the client and server pages. I need to connected to a database, but when I run the server first it is working. Starting the Server then I run the client page, I got the error was display SEVERE: null. I don't why. I have attached code below. I have a problem with client page. Is there any thing wrong? What I tried I attached below. Give the solution for it, thanks.</p>
  <p><strong>publisher.java</strong></p>
  <pre><code>public class publisher {
      
      String id;
      String pname;
      String price;
      String qty;
  
  public static void main(String args[])
  {
     new publisher(); 
  
  }
  }
  </code></pre>
  <p><strong>Server.java</strong></p>
  <pre><code>import java.io.*;
  import java.sql.*;
  import java.net.*;
  import java.util.*;
  import java.util.logging.Level;
  import java.util.logging.Logger;
  import javax.swing.table.DefaultTableModel;
  
  public class Server extends Thread {
  
      Statement stmt=null;
      Vector records = new Vector(10,10);
      ResultSet rs = null;
      ServerSocket server = null;
      Socket client = null;
      Connection con = null;
      ObjectOutputStream out =null;
      String str = null;
      publisher pub = null;
      
      public Server()
      {
          try {
              server = new ServerSocket(1700);
              System.out.println(&quot;Starting the Server&quot;);
              start();
          } catch (IOException ex) {
              Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
          }
          
      }
      
      public void run()
      {
          while(true)
          {
              try {
                  int CC;
                  client = server.accept();
                  System.out.println(&quot;Connection accepted&quot;);   
                  out = new ObjectOutputStream(client.getOutputStream());
                  System.out.println(&quot;OutputStream received&quot;);
                  try {
                      Class.forName(&quot;com.mysql.jdbc.Driver&quot;);
                      con = DriverManager.getConnection(&quot;jdbc:mysql://localhost/smobile&quot;, &quot;root&quot;,&quot;&quot;);
                      stmt = con.createStatement();
                      rs = stmt.executeQuery(&quot;select * from products&quot;);
                      records.removeAllElements();
  
              ResultSetMetaData RSMD = rs.getMetaData();
              CC = RSMD.getColumnCount();
                      
                      
                      
                      while(rs.next())
                      {
                          pub = new publisher();
                          pub.id = rs.getString(1);
                          pub.pname = rs.getString(2);
                          pub.price = rs.getString(3);
                          pub.qty = rs.getString(4);
                          records.addElement(pub);
                          System.out.println(&quot;row returned&quot;);
                      }
  
                      out.writeObject(records);
                      out.close();
                      System.out.println(&quot;String returned&quot;);
                      
                      
                  } catch (ClassNotFoundException ex) {
                      Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
                  } catch (SQLException ex) {
                      Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
                  }
            
                   
                   
                   
                   
              } catch (IOException ex) {
                  Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
              }
              
          }
      }
      public static void main(String args[])
  {
     new Server(); 
  
  }
  
  
  
  Client.java
  
       String str = &quot;&quot;;
             ResultSet rs;
             Vector records;
             publisher pub = null;
             int a = 0;
             ObjectInputStream br = null;
             Connection con;
             PreparedStatement pst;
  
             private void table_update() 
  {
              int i = 0;
                   Socket socket1;
              try {
                  socket1 = new Socket( &quot;192.168.225.1&quot;, 1700);
                   System.out.println(&quot;client is now connected with server&quot;);
              
                  br = new ObjectInputStream(socket1.getInputStream());
                  records = (Vector)br.readObject();
       
                  DefaultTableModel DFT = (DefaultTableModel) jTable1.getModel();
                  DFT.setRowCount(0);
      
                  while (i &lt; records.size()) {
                      Vector v2 = new Vector();
                       pub = (publisher)records.elementAt(i);
                  
                          v2.add(pub.id);
                          v2.add(pub.pname);
                          v2.add(pub.price);
                          v2.add(pub.qty);
                             i++;
                          DFT.addRow(v2);
                          
                      }
      
                      
                  } catch (IOException ex) {
                  Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex);
              } catch (ClassNotFoundException ex) {
                  Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex);
              }
  </code></pre>
  <p><strong>Error displayed</strong></p>
  <pre><code>Client table_update
  SEVERE: null
  java.io.EOFException
      at java.io.ObjectInputStream$BlockDataInputStream.peekByte(ObjectInputStream.java:3014)
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1575)
      at java.io.ObjectInputStream.readObject(ObjectInputStream.java:464)
      at java.io.ObjectInputStream.readObject(ObjectInputStream.java:422)
      at Client.table_update(Client.java:62)
      at Client.&lt;init&gt;(Client.java:22)
  </code></pre>