dimanche 12 mars 2017

Inserting multiple rows into database table using JAVA

I need to insert multiple rows (about 1 mln.) containing random numbers into a Postgresql database. This code generates one row with random numbers into a database. How can i make the statement loop itself for any amount of times?

        Random rand = new Random();
        for (int j=0;j < 1;j++);

            stmt = c.createStatement();
            String sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) "
                    + "VALUES ('" + rand.nextInt() + "', '" + rand.nextInt() + "', '" + rand.nextInt() + "', '" + rand.nextInt() + "'," +
                    " '" + rand.nextInt() + "')";
            stmt.executeUpdate(sql);

        stmt.close();
        c.commit();
        c.close();




Aucun commentaire:

Enregistrer un commentaire