我想要一个包含查询结果的字符串的数组,并且该数组不添加任何值。我已经在数据库中键入了查询,它可以正常工作。
public String[] query() {
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/repaso?" + "user=root&password=");
Statement sentence = con.createStatement();
ResultSet result = sentence.executeQuery("select marca from marca");
result.last();
int i = result.getRow();
result.beforeFirst();
System.out.println(result);
int x = 0;
String[] array = new String[i];
while (result.next()) {
array[x] = result.getString(1);
x++;
}
result.close();
return array;
} catch (ClassNotFoundException | SQLException e1) {
}
return null;
}