⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 resultset.java

📁 java patterns book
💻 JAVA
字号:
import java.sql.*;
class resultSet
{
//this class is a higher level abstraction
//of the JDBC ResultSet object
   ResultSet rs;
   ResultSetMetaData rsmd;
   int numCols;

   public resultSet(ResultSet rset)
   {
      rs = rset;
      try
      {
      //get the meta data and column count at once
      rsmd = rs.getMetaData();
      numCols = rsmd.getColumnCount();
      }
      catch (Exception e)
      {System.out.println("resultset error"+e.getMessage());}
   }
   //-----------------------------------
   public String[] getMetaData()
   {
    //returns an array of all the column names
    //or other meta data
      String md[] = new String[numCols];
      try
         {
      for (int i=1; i<= numCols; i++) 
         md[i-1] = rsmd.getColumnName(i);
      }
      catch (Exception e)
      {System.out.println("meta data error"+e.getMessage());}
      return md;
   }
   //-----------------------------------
   public boolean hasMoreElements()
   {
      try{
      return rs.next();
      }
   catch(Exception e){
      System.out.println("next error "+e.getMessage());
      return false;}
   }
   //-----------------------------------
   public String[] nextElement()
   {
   //copies contents of row into string array
      String[] row = new String[numCols];
      try
      {
      for (int i = 1; i <= numCols; i++) 
            row[i-1] = rs.getString(i);
      }
      catch (Exception e)
      {System.out.println("next element error"+e.getMessage());}
    return row;
   }
   //-------------------------------------
   public String getColumnValue(String columnName)
   {
   String res = "";
     try 
     {
     res = rs.getString(columnName);
     }
   catch (Exception e)
   {System.out.println("Column value error:"+columnName+e.getMessage());}
   return res;
   }
   //-------------------------------------
   public String getColumnValue(int i)
   {
   String res = "";
     try 
     {
     res = rs.getString(i);
     }
   catch (Exception e)
   {System.out.println("Column value error: " + i + " " + e.getMessage());}
   return res;
   }
   //----------------------------------------------
   public void finalize()
   {
    try{rs.close();}
    catch (Exception e)
      {System.out.println(e.getMessage());}
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -