자바 액세스 데이터베이스 sql server 첨삭 검사 세 번 째 편

1813 단어
xsxx.java
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Vector;
import javax.swing.table.*;

class xsxx extends AbstractTableModel 
{
	Vector ziduan,jilu;
	PreparedStatement ps=null;
    Connection ct=null;
    ResultSet rs=null;
    
	public int getRowCount()//      ,AbstractTableModel           (       ),
	//         。JTable                。
	{
		return this.jilu.size();
		
	}
    public int getColumnCount()//      ,JTable                         。
    {
		return this.ziduan.size();
	}
	public Object getValueAt(int hang, int lie)//                。
	{
		return ((Vector)this.jilu.get(hang)).get(lie);
	}
	
	public xsxx()
	{
		this.sqlyj("select * from Table_3");
	}
	public xsxx(String ss)
	{
		this.sqlyj(ss);
	}
	public String getColumnName(int e)//   e        .
	{
		return (String)this.ziduan.get(e);
	}
	public void sqlyj(String sql)
	{
		ziduan=new Vector();
		ziduan.add("  ");
		ziduan.add("  ");
		ziduan.add("  ");
		ziduan.add("  ");	
		
        jilu=new Vector();
		
		try {
	    	  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
			  ct=DriverManager.getConnection("jdbc:odbc:sql server");
			  ps=ct.prepareStatement(sql);	
			  rs=ps.executeQuery();
			  
			  while(rs.next())
			  {
				  Vector hang=new Vector();
					hang.add(rs.getString(1));
					hang.add(rs.getString(2));
					hang.add(rs.getString(3));
					hang.add(rs.getString(4));
					jilu.add(hang);
			  }
		} catch (Exception e){}
	    finally
	    {
	    	try {
	    		if(rs!=null)
				{
					rs.close();
				}
	    		if(ps!=null)
				{
					ps.close();
				}
				if(ct!=null)
				{
					ct.close();
				}
				
			} catch (Exception e){}
	    }
	}
}

좋은 웹페이지 즐겨찾기