Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public sqlconnection()
- {
- try
- {
- Connection myConn = DriverManager.getConnection( "jdbc:mysql://localhost:3306/userlogin","jeddy","admin");
- insertIntoDB();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- public void insertIntoDB() throws SQLException
- {
- try
- {
- String driver ="com.mysql.jdbc.Driver";
- Class.forName(driver);
- String inpUsername=console.readLine("Enter username: ");
- String inpPassword=console.readLine("Enter password: ");
- String sql = ("insert into user(username, password) values('"+inpUsername+"', '"+inpPassword+"')");
- PreparedStatement pStmt = myConn.prepareStatement(sql);
- pStmt.executeUpdate();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
Add Comment
Please, Sign In to add comment