Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.util.Random;
- import java.lang.StringBuilder;
- public class pvz {
- public static void main(String args[]) {
- Connection c = null;
- PreparedStatement smt = null;
- try {
- Class.forName("org.postgresql.Driver");
- c = DriverManager
- .getConnection("jdbc:postgresql://localhost:5432/naujasTEST",
- "postgres", "kurmis");
- c.setAutoCommit(false);
- System.out.println("Opened database successfully");
- Random rand = new Random();
- StringBuilder sql = new StringBuilder("INSERT INTO COMPANY3 (ID,NAME,AGE,ADDRESS,SALARY) + VALUES;");
- for (int j=0; j < 10; j++) {
- if (j == 1) sql.append(",");
- sql.append("(" + j + /* ID */
- ",'" + rand.nextInt() + "'" + /* NAME */
- ",'" + rand.nextInt() + "'" + /* AGE */
- ",'" + rand.nextInt() + "'" + /* ADDRESS */
- ",'" + rand.nextInt() + "'" + /* SALARY */
- ")");
- }
- //smt = c.createStatement();
- smt.executeUpdate();
- smt.close();
- c.commit();
- c.close();
- } catch (Exception e) {
- System.err.println( e.getClass().getName()+": "+ e.getMessage() );
- System.exit(0);
- }
- System.out.println("Records created successfully");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement