jdbc insert example from input values

Solutions on MaxInterview for jdbc insert example from input values by the best coders in the world

showing results for - "jdbc insert example from input values"
Valentina
11 Feb 2019
1// 0. read user input from command line: last name, first name and email
2Scanner scanner = new Scanner(System.in);
3
4System.out.print("Enter your last name: ");
5String lastName = scanner.nextLine();
6System.out.print("Enter your first name: ");
7String firstName = scanner.nextLine();
Beatrice
08 Sep 2019
1// 2. Create a statement
2	String sql = "insert into employees "
3			+ " (last_name, first_name)" + " values (?, ?)";
4	myStmt = myConn.prepareStatement(sql);
5	// set param values
6	myStmt.setString(1, lastName);
7	myStmt.setString(2, firstName);
8	// 3. Execute SQL query
9	myStmt.executeUpdate();
10