Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void createUser(){
- user.add(username);
- user.add(password);
- user.add(email);
- user.add(picture);
- //connect to database
- try {
- Class.forName("com.mysql.jdbc.Driver");
- try {
- connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/myFacebook?" + "user=root&password=root");
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- //Insert Data into database
- try(PreparedStatement createUser = connection.prepareStatement("Insert into user(username, password, email, picture)" + "VALUES (?, ?, ?, ?)")){
- for(int i = 0; i < 1000; i++)
- {
- createUser.setInt(1, i+1);
- createUser.setString(2, user.get(0));
- createUser.setString(3, user.get(1));
- createUser.setString(4, user.get(2));
- createUser.setString(5, user.get(3));
- }
- int rowsUpdated = createUser.executeUpdate();
- createUser.close();
- }catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- try {
- connection.close();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- ArrayList<String> user = new ArrayList<String>();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement