我想在SQL数据库的文本区域中显示整个列,但在TextArea中,它只显示最后一行数据。解决方案是什么?
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection("jdbc:oracle:oci8:@localhost:1521:XE","tushar","yahoo123");
st=con.createStatement();
rs=st.executeQuery("select CUSTOMER_ID from demo_customers" );
while(rs.next())
{
String CUSTOMER_ID = rs.getString("CUSTOMER_ID");
t2.setText("ID: " + CUSTOMER_ID); //JTextArea t2=new TextArea();
}
st.close();
con.close();
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
答案 0 :(得分:3)
您应该将新文本追加,而不是设置每行的新值。添加换行符也是一个好主意:
while(rs.next()) {
String CUSTOMER_ID = rs.getString("CUSTOMER_ID");
t2.append("ID: " + CUSTOMER_ID+"\n");
}