create and insert values using mysql JDBC

Posted by S.PRATHIBA on Stack Overflow See other posts from Stack Overflow or by S.PRATHIBA
Published on 2010-03-30T04:20:26Z Indexed on 2010/03/30 4:23 UTC
Read the original article Hit count: 179

Filed under:
|
|

Hi all,

I have the sample code.

public void UpdateTable1() { for(int t=0;t<20;t++) {

if(consumer==1 && number==1 && provider1==31 && feedback==1) {

try{

  Class.forName(driverName);


  con = DriverManager.getConnection(url+dbName,"root","mysql");


  try

    {


    Statement st = con.createStatement();


    int val = st.executeUpdate("INSERT Consumer1 VALUES ("+31+","+"'Printer'"+", "+1+" "+")");


    System.out.println("1 row affected");

  }
  catch (SQLException s)
    {

    System.out.println("SQL statement is not executed!");

  }


 con.close();

}

I want to insert the same set of values(31,printer,1) into the table consumer2,consumer3.Is it possible without using another try catch statements...Please help me.

© Stack Overflow or respective owner

Related posts about java

Related posts about and