Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class AddStudent
- {
- public static void main (String[] args)
- {
- try
- {
- Connection conn = DriverManager.getConnection(url,user,pass);
- Statement st = conn.createStatement();
- Scanner first = new Scanner(System.in);
- System.out.println(first.nextLine());
- String SQL = "INSERT INTO test VALUES ('Cathy', 'Jones')";
- st.executeUpdate(SQL);
- conn.close();
- } catch (Exception e) {
- System.err.println("Got an exception! ");
- System.err.println(e.getMessage());
- }
- }
- private static String url = "jdbc:mysql://localhost:3306/registrar";
- Scanner first = new Scanner(System.in);
- String f = first.nextLine();
- Scanner last = new Scanner(System.in);
- String l = last.nextLine();
- String SQL = "INSERT INTO test VALUES ('" + f + "','" + l + "')";
- st.executeUpdate(SQL);
- PreparedStatement ps = conn.prepareStatement("INSERT INTO test VALUES (?, ?)");
- ps.setString(1, f);
- ps.setString(2, l);
- ps.executeUpdate();
- String firstName = "Cathy";
- String lastName = "Jones";
- String query= "INSERT INTO test VALUES (?,?)";
- PreparedStatement stmt = mysqlConnection.prepareStatement(query);
- stmt.setString(1,firstName);
- stmt.setString(2,lastName);
- stmt.executeUpdate(SQL);
- Scanner scanner = new Scanner(System.in);
- String first = scanner.nextLine();
- String last = scanner.nextLine();
- String SQL = "INSERT INTO test VALUES ('Cathy', 'Jones')";
- st.executeUpdate(SQL);
- String SQL = String.format("INSERT INTO test VALUES ('%s', '%s')", first, last);
- st.executeUpdate(SQL);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement