有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java需要帮助通过PreparedStatement编写适当的搜索查询

现在我正在尝试制作一个Java控制台应用程序,目的是更容易填充我的数据库(我刚刚开始学习Java,所以请原谅我使用了这个术语)

我正在使用Hibernate和JDBC。所以我上了几门课,其中两门是乡村课和城市课。首先,我将填充国家,接下来我将填充城市,因为我将它们与一对多(国家->;城市)联系起来

我需要编写一个方法,从Scanner中接受字符串countryname,在Country表中搜索它,然后返回这个国家的id。我需要关于编写MySQL查询的帮助

public static countrySearch(String countryname){

    try {
        Connection connection = DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/freeguide", "root", "6235");
        PreparedStatement ps = connection.prepareStatement("select id from Country where countryname LIKE (?) ");
        //Here is where I am stuck

    }    

    catch (SQLException e) {    
        e.printStackTrace();
    }
    return countryid;

}

共 (0) 个答案