Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // registers new user and returns his instance
- public void registerUser(String login, String password, String mail, String name)
- {
- try
- {
- Statement stmt;
- Class.forName("com.mysql.jdbc.Driver");
- String url = "jdbc:mysql://localhost:3306/mysql";
- Connection con = DriverManager.getConnection(url,"root", "");
- System.out.println("URL: " + url); // debug
- System.out.println("Connection: " + con);
- stmt = con.createStatement();
- stmt.executeUpdate("INSERT INTO user(login, pass, mail, name) VALUES('"+login+"', '"+password+"', '"+mail+"', '"+name+"')");
- // gets last insertionid
- ResultSet rs = stmt.getGeneratedKeys();
- int lastInsertedId = rs.getInt(1);
- this.id = lastInsertedId;
- this.login = login;
- this.name = name;
- this.mail = mail;
- this.name = name;
- con.close();
- }
- catch( Exception e )
- {
- System.out.println(e.getStackTrace()); // chyba
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement