/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */


import java.sql.Connection;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Vector;

import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author My PC
 */
public class tracuuphong {

    Connection c = new getconect().getcon();
    String loai;
    String quanly;
    Vector row,column;
    int numbercolumn;
	public DefaultTableModel tb=new DefaultTableModel();
    public tracuuphong(int khu, String phong, String loai, String quanly,DefaultTableModel tb) {
        if (phong.length() == 0) {
            JOptionPane.showMessageDialog(null, "Bạn cần nhập từ khóa để tìm", "Thông báo", 1);
            
        } else {
            try {
                Statement stmt = c.createStatement();
                String sql="select loaiphong,quanlynha from nha,phong where nha.tennha=phong.nha and maph='"+phong+"';";
                ResultSet rs1=stmt.executeQuery(sql);
                while(rs1.next()){
                this.quanly=rs1.getString(2);
                this.loai=rs1.getString(1);
                }

                column = new Vector();
                String sql1="select mssv,ten,khoa,ngayvao from sinhvien where maph = '"+phong+"';";
                ResultSet rs2=stmt.executeQuery(sql1);
                ResultSetMetaData metaData=rs2.getMetaData();
                numbercolumn=metaData.getColumnCount();
                for(int i=1;i<=numbercolumn;i++){
                	column.add(metaData.getColumnName(i));
                }
                this.tb.setColumnIdentifiers(column);
                while(rs2.next()){
                	row=new Vector();
                	for(int i=1;i<=numbercolumn;i++){
                		row.add(rs2.getString(i));
                	}
                	this.tb.addRow(row);
                }
                
                stmt.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }

        }
    }



}

@@ -550,27 +550,20 @@
 loai
-;%0A    String 
+,
 quanly
+,khui
 ;%0A  
@@ -764,16 +764,157 @@
         
+if(khu==0)khui=%22b5%22;%0A        if(khu==1)khui=%22b6%22;%0A        if(khu==3)khui=%22b7%22;%0A        String maphong;%0A        maphong= khui+%22-%22+phong;%0A    %09
 if (phon
@@ -1240,16 +1240,18 @@
 maph='%22+
+ma
 phong+%22'
@@ -1483,32 +1483,32 @@
 = new Vector();%0A
-
                 
@@ -1579,16 +1579,18 @@
 ph = '%22+
+ma
 phong+%22'

edit tracuuphong