title: How to print a JTable object in the Java application
body: <p><strong>Question</strong> Now once the data is fetched from the database and shown in the JTable object "table" embedded in the scrollPane, how do we create a print job that makes it possible to print the displayed table as such in A3 sized paper ?</p>
  
  <p>My code to fetch the data from the database is shown below:</p>
  
  <pre><code>try 
  {
      Class.forName("com.mysql.jdbc.Driver"); 
      Connection con=DriverManager.getConnection("jdbc:mysql://localhost/newb","root","pass");
      Statement stat=con.createStatement();   
      ResultSet res=stat.executeQuery("select * from table where name = '"+name+"'");
      ResultSetMetaData rsmd = res.getMetaData();
      int colcount = rsmd.getColumnCount();
      Vector columns = new Vector(colcount);
          for(int i=3; i&lt;=colcount; i++)
      {
          columns.add(rsmd.getColumnName(i));
      }
      Vector data = new Vector();
      Vector row;
  
      // Store row data
      while(res.next())
      {
          row = new Vector(colcount);
          for(int i=3; i&lt;=colcount; i++)
          {
              row.add(res.getString(i));
          }
          data.add(row);
      }
      table = new JTable(data, columns);
      table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
      scrollPane.setViewportView(table);
  }
  catch(Exception ex)
  {       
      System.out.println(ex);
  }
  </code></pre>
  
  <p>I am using vector class to fetch the data from the table. How do we print the data shown in the displayed table to a paper? </p>