I am having some trouble with the below code for my assignment. I am trying to display thein theline. But for some reason theJTextAreadisplays blank when called inlineDoes anyone know how I can go about getting the information fromvoid addComponents()inlinepublic searchProps(int propID)
import java.awt.Container; import java.sql.*; import java.util.*; import javax.swing.*; public class searchProps { protected String price, area, query, suburb, date, SaleOrRent, strQuery, line=""; protected int agentID, upid, StreetNum, numBeds, numBaths, numGarages, ownerID, size; protected boolean spool; PropertyObject PropertyArray[] = new PropertyObject[3]; JFrame jf; JTextArea txtArea = new JTextArea(); { initialFrame(); addComponents(); } public searchProps(int propID) //search using UPID only { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection conn = DriverManager.getConnection("jdbc:odbc:PropertyOracleDatabase"); Statement s = conn.createStatement(); query = ("SELECT * FROM Properties WHERE UPID = "+propID); // Fetch table s.execute(query); ResultSet rs = s.getResultSet(); while((rs!=null) && (rs.next())) { upid=rs.getInt(1); StreetNum=rs.getInt(2); suburb=rs.getString(3); area=rs.getString(4); price=rs.getString(5); agentID= rs.getInt(6); numBeds=rs.getInt(7); numBaths=rs.getInt(8); spool=rs.getBoolean(9); numGarages=rs.getInt(10); date=rs.getString(11); ownerID=rs.getInt(12); SaleOrRent=rs.getString(13); size++; // line = (line+upid+"\t"+StreetNum+"\t"+suburb+"\t"+area+"\t"+price+"\t"+agentID+"\t"+numBeds+"\t"+numBaths+"\t"+spool+"\t"+numGarages+"\t"+date+"\t"+ownerID+"\t"+SaleOrRent+"\n"); System.out.println(line); } // close and cleanup s.close(); conn.close(); } catch(Exception ex) { ex.printStackTrace(); } } void initialFrame() { jf=new JFrame(); jf.setSize (1300,700); jf.setTitle("Property Oracle | Results Page"); jf.setVisible(true); jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } void addComponents() { Container con = jf.getContentPane(); String out = this.getLine(); con.setLayout(null); txtArea.setBounds(20,30,1200,600); con.add(txtArea); txtArea.setText("UPID\tStreetNum\tSuburb\tArea\tPrice\tAgentID\tBedrooms\tBathrooms\tSwimming Pool\tGarages\tDate\tOwner\tSale/Rent\n"); System.out.println(line); } }
Thanks!