我是一名初学者,并且在 JAVA 中对我的数据库进行了多次成功查询,但我的一个查询返回了我不理解的内容。打印的是: [Ljava.lang.String;@6b081032 实际上应该打印的是条件名称。因此,如果我的查询假设返回 7 个条件名称,它将打印“[Ljava.lang.String;@6b081032”七次。
下面是我正在测试我一直遇到问题的方法的代码。“[Ljava.lang.String;@6b081032”是什么意思?谢谢。
public class Test {
static String url = "jdbc:mysql://localhost:3306/masters"; //providing the host, port and database name
static String username = "christine";
static String password = "password";
static PreparedStatement pst = null;
static ResultSet rs = null;
public static void main(String[] args) throws IOException{
String[] test = dxNameByName(2);
for(int i=0; i<test.length; i++)
{
System.out.println(test);
}
}
public static String[] dxNameByName(int num){
Connection con = null;
ArrayList<String> list= new ArrayList<String>();
String[] result = new String[list.size()];
try{
con = DriverManager.getConnection(url, username, password); //establishes a connection to the database
pst = con.prepareStatement("SELECT * FROM diagnosis WHERE diag_region_fk = '" + num+ "';");
rs = pst.executeQuery();
while (rs.next())
{
list.add(rs.getString("diagnosis_name"));
}
result = list.toArray(result);
}catch(SQLException e){
e.printStackTrace();
}
finally{
try { if (rs != null) rs.getStatement().close(); } catch (Exception e) {};
try { if (pst != null) pst.close(); } catch (Exception e) {};
try { if (con != null) con.close(); } catch (Exception e) {};
}
return result;
}
}