Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void salePropertyActionPerformed(java.awt.event.ActionEvent evt) {
- String sSelectQuery = "";
- Statement statement=null;
- Connection conn = null;
- //PreparedStatement pStatement =null;
- Vector columnNames = new Vector();
- Vector data = new Vector();
- JPanel panel= spPanel;
- try {
- String myDriver = "com.mysql.jdbc.Driver";
- String myURL = "jdbc:mysql://localhost:3306/realestate?autoReconnect=true&useSSL=false";
- Class.forName(myDriver);
- conn=DriverManager.getConnection(myURL,"username","password");
- /*Storing SQL statement*/
- sSelectQuery ="SELECT propertyID, propertyPrice FROM property";
- statement = conn.createStatement();
- try (ResultSet rs = statement.executeQuery(sSelectQuery) //executes the query
- ) {
- ResultSetMetaData metaData = rs.getMetaData();
- int columns = metaData.getColumnCount();
- for(int i = 1; i<=columns; i++){
- columnNames.addElement(metaData.getColumnName(i));
- }
- while (rs.next()){
- Vector row = new Vector(columns);
- for (int i=1; i<=columns; i++){
- row.addElement(rs.getObject(i));
- }
- data.addElement(row);
- System.out.println(data);
- }
- rs.close();
- JTable spTable = new JTable(data,columnNames);
- TableColumn column;
- for (int i=0; i<spTable.getColumnCount(); i++){
- column=spTable.getColumnModel().getColumn(i);
- //column.setMaxWidth(250);
- }
- JScrollPane scrollPane = new JScrollPane(spTable);
- panel.add(scrollPane);
- }
- statement.close();
- } catch (SQLException e) {
- System.err.println("An exception ocurred");
- System.err.println(e.getMessage());
- } catch (ClassNotFoundException ex) {
- Logger.getLogger(realEstateUI.class.getName()).log(Level.SEVERE, null, ex);
- }
- JOptionPane.showMessageDialog(this,"Query Complete");
- }
- /**
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement