小编use*_*797的帖子

麻烦转义String.matches()方法中的句点

当我在String类的matches()方法中使用这个正则表达式时,我收到了编译错误.谁知道我在做错了什么?谢谢

String email = "this@that.com";
System.out.println(email.matches("^(.+@.+\.\\w{2,4})$"));
Run Code Online (Sandbox Code Playgroud)

java regex escaping period

2
推荐指数
1
解决办法
7030
查看次数

使用 getGeneratedKeys() Java

谁能看到我是如何错过这个 ResultSet 的?我收到以下错误customerID = rs.getInt(1)

public boolean addCustomer(Customer customer) {
    String customerSQL = "INSERT INTO Customer (first_name, last_name)"
            + "VALUES (?, ?)";
    String emailSQL = "INSERT INTO Email (customer_ID, email_address, primary_email)"
            + "VALUES (?,?,?)";
    int customerID = 0;

    try (Connection connection = getConnection();
            PreparedStatement customerPs = connection.prepareStatement(
                    customerSQL, new String[] {"CUSTOMER_ID"});
            //PreparedStatement idPs = connection.prepareStatement(idSQL);
            //PreparedStatement emailPs = connection.prepareStatement(emailSQL)
            )  {

        customerPs.setString(1, customer.getFirstName());
        customerPs.setString(2, customer.getLastName());
        customerPs.executeUpdate();
        ResultSet rs = customerPs.getGeneratedKeys();

        System.out.println("Result Set: " + rs.toString());
        customerID = rs.getInt(1); …
Run Code Online (Sandbox Code Playgroud)

java jdbc

1
推荐指数
1
解决办法
3963
查看次数

标签 统计

java ×2

escaping ×1

jdbc ×1

period ×1

regex ×1