我無法將結果集的值存入String [] []中。它示出了在線路13.如果NullPointerExceptions的我直接打印rs.getString(0)和rs.getString的值(1),它正常我無法將結果集的值存儲到二維字符串數組中
public void get_papers(String a_id)
{
int aid=Integer.parseInt(a_id);
String[][] s1=new String[2][];
try
{
int i=0;
Connection con=DriverManager.getConnection(url,"root","");
Statement s=con.createStatement();
ResultSet rs=s.executeQuery("select title,p_s_no from paper_record where a_id='"+aid+"'");
while(rs.next())
{
s1[0][i]=(String)rs.getString(1);
s1[1][i]=(String)rs.getString(2);
i++;
}
}
catch(SQLException se)
{System.out.println(se);}
//return(s1);
System.out.println(s1[0][1]);
System.out.println(s1[1][1]);
}
'a_id'似乎是表格的唯一標識符(主鍵)。如果是這樣,爲什麼你迭代(唯一的)結果集? – Hannes 2014-09-13 05:25:47