Reputation: 37
I want to show the whole column in the text area from the SQL database but in the TextArea it's only showing last row data. What is the solution?
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());
}
Upvotes: 2
Views: 105
Reputation: 13858
Instead of setting your text to a new value for each row, you should append the new text to the one you previously had. Adding linebreaks might be a good idea as well:
while(rs.next()) {
String CUSTOMER_ID = rs.getString("CUSTOMER_ID");
t2.append("ID: " + CUSTOMER_ID+"\n");
}
Upvotes: 3