Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.Statement;
  4. import java.util.ArrayList;
  5. import java.util.Random;
  6.  
  7. public class new_test {
  8.  
  9. public static void main(String[] args) {
  10. ArrayList<String>objectsToStore = new ArrayList<>();
  11.  
  12. Random rad = new Random();
  13.  
  14. for (int j=1; j<=1; j++ )
  15. {
  16. objectsToStore.add("usename"+rad.nextInt()+"@gmail.com");
  17.  
  18. }
  19.  
  20. try {
  21.  
  22. Class.forName("com.mysql.jdbc.Driver") ;
  23.  
  24. Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?useSSL=false", "root", "");
  25.  
  26. connection.setAutoCommit(false);
  27. Statement statement = connection.createStatement();
  28.  
  29. for (String objectsToStore : objectsToStore ) {
  30.  
  31. statement.executeUpdate("INSERT INTO USER_DATA (email) VALUES ('" +objectsToStore +"')");
  32. }
  33.  
  34. connection.commit();
  35. statement.close();
  36. connection.close();
  37.  
  38. } catch (Exception e) {
  39. throw new RuntimeException(e);
  40. }
  41.  
  42. }
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement