Advertisement
Guest User

Untitled

a guest
Nov 25th, 2016
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. public void createUser(){
  2.  
  3.  
  4. user.add(username);
  5. user.add(password);
  6. user.add(email);
  7. user.add(picture);
  8.  
  9.  
  10. //connect to database
  11. try {
  12. Class.forName("com.mysql.jdbc.Driver");
  13.  
  14. try {
  15.  
  16. connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/myFacebook?" + "user=root&password=root");
  17.  
  18. } catch (SQLException e) {
  19. // TODO Auto-generated catch block
  20. e.printStackTrace();
  21. }
  22. } catch (ClassNotFoundException e) {
  23. // TODO Auto-generated catch block
  24. e.printStackTrace();
  25. }
  26.  
  27.  
  28. //Insert Data into database
  29. try(PreparedStatement createUser = connection.prepareStatement("Insert into user(username, password, email, picture)" + "VALUES (?, ?, ?, ?)")){
  30. for(int i = 0; i < 1000; i++)
  31. {
  32. createUser.setInt(1, i+1);
  33. createUser.setString(2, user.get(0));
  34. createUser.setString(3, user.get(1));
  35. createUser.setString(4, user.get(2));
  36. createUser.setString(5, user.get(3));
  37. }
  38. int rowsUpdated = createUser.executeUpdate();
  39. createUser.close();
  40. }catch (SQLException e) {
  41. // TODO Auto-generated catch block
  42. e.printStackTrace();
  43. }
  44. try {
  45. connection.close();
  46. } catch (SQLException e) {
  47. // TODO Auto-generated catch block
  48. e.printStackTrace();
  49. }
  50. }
  51.  
  52. ArrayList<String> user = new ArrayList<String>();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement