title: How to add data (Jtable data actually) into database. Is there any way to insert an object into database using preparedstmt?
body: <pre><code>public cntctus() 
  {
  </code></pre>
  
  <p>column names for <code>JTable</code></p>
  
  <pre><code>    String column[]= { "Name","Position","Phone"};
  </code></pre>
  
  <p>rows for <code>JTable</code></p>
  
  <pre><code>    Object [][]row = {
              {"Prof. Renu Vig", "Director", "+123456"},
              {"Mr. Sukhbir singh", "Assistant Professor", "+9123568989"},
              {"Ms. shaweta", "BI teacher","9468645"}
      };
  
  
      table = new JTable(row,column);
      TableModel tm = table.getModel();
      java.sql.Connection con=null;
      try {
          Class.forName("com.mysql.jdbc.Driver");
  con=DriverManager.getConnection("jdbc:mysql://localhost:3306/training","root","");
       try{
           java.sql.Statement stmt =con.createStatement();
  String maketable = "CREATE TABLE if not exists contacttable(Name Varchar(25),Position Varchar(20),Phone Varchar(20))";
           stmt.executeUpdate(maketable);
          System.out.print("table created ");
  //insert into table contacttable query 
  
  PreparedStatement pstmt=con.prepareStatement("INSERT into contacttable select     distinct    values(?,?,?)");
  </code></pre>
  
  <p>get some <code>TableModel</code> that will contain the data</p>
  
  <pre><code>        for (int i = 0; i &lt; tm.getRowCount(); i++) {
            for (int j = 0; j &lt; tm.getColumnCount(); j++) {
              Object o = tm.getValueAt(i, j);
  
  
   System.out.println("object from table is  : " +o);
   k=j+1;          
   pstmt.setString(k, (String)o);
    }
   pstmt.executeUpdate();
          }
  
        }
       catch(SQLException s)
          {
              System.out.println(s);
          }
      }
       catch(Exception e)
          {
              e.printStackTrace();
           }
  </code></pre>
  
  <p>I want to insert this whole object into database.in short how to insert jtable data into databse.?? please help. </p>
  
  <p>error is: <strong>you have an error in your sql syntax at line 1 ('"prof. renu vig, "director"...</strong></p>