【发布时间】:2017-11-08 07:36:58
【问题描述】:
这是我在 netbeans 中的 web 服务 java 项目的一部分。 我不知道如何从我的数据库中检索 两个值(描述 + 文化 - 这些是列),将它们添加到数组,然后检索它们都强>稍后。 当只检索 一个 值时,我知道如何做到这一点。
public String countries(@WebParam(name = "name") String name) {
//TODO write your implementation code here
try {
String url = "jdbc:odbc:" + "worldcup";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection(url,"","");
// Gets a statement
Statement state1 = con.createStatement();
//Statement state2 = con.createStatement();
String query1 = "SELECT description,culture FROM Countries WHERE name = '" + name + "'";
// selects the description for the selected group ( group will be referenced to the chosen group)
ResultSet results = state1.executeQuery(query1);
int i = 0;
Arrays.fill(names, "");
while (results.next()) {
String nam = results.getString("description"); // <---- this is the part i need help from
names[i++] = nam;
}
return Arrays.toString(names);
} catch (SQLException e){
e.printStackTrace();
} catch (ClassNotFoundException e) {
}
return null;
【问题讨论】:
-
String nam = results.getString("description") + " "+results,getString("culture");
-
谢谢!!有道理,我不知道如何组合它们。
-
我会创建 Country 类的对象。对于 ResultSet 中的每一行。
标签: java arrays database resultset