***怎么样在javabean里面写数据库处理语句,在jsp显示结果?***能给个例子么?我是用weblogic建立的jdbc连接,不会自己编写连接包,也看不懂别人用自己编写的连接包写的javabean。。因为用到他编写的包的地方的语句我不知道怎么替代。

解决方案 »

  1.   

    在javaBean里面写数据库是不符合java规范的哟
      

  2.   

     mainBean.java   
      ==============================   
        
      package   ylb;   
      import   java.sql.*;   
      import   java.util.*;   
      import   pubpkg.ExecDb;   
        
      public   class   mainBean   {   
          private   String   xmlData;   
          int   rows,   cols;   
          Vector   result;   
          //private   ExecDb   conn;   
          public   Vector   getData()   throws   Exception{   
              ExecDb   conn   =   new   ExecDb();   
              String   tableStr   =   "";   
              String   sql   =   "select   *   from   a111a410_grid1";   
              ResultSet   rs;   
              rs   =   conn.executeQuery(sql);   
        
              ResultSetMetaData   rsmd   =   rs.getMetaData();   
              cols   =   rsmd.getColumnCount();   
        
              rows   =   0;   
              result   =   new   Vector();   
              String   s[]   =   new   String[cols];   
              for   (int   i=1;   i<=cols;   i++)   {   
                      s[i-1]   =   rsmd.getColumnLabel(i)   ;   
              }   
        
              result.addElement(s);   
              rows   ++;   
              //   for   entire   data   
              while   (rs.next())   {   
                  s   =   new   String[cols];   
                  //   for   one   row   
                  for   (int   i=0;   i<cols;   i++)   {   
                            s[i]   =   rs.getString(i+1);   
                    }   
                    result.addElement(s);   
                    rows   ++;   
            }   
              return   result;   
          }   
        
          public   int   getColumnCount()   {   
              return   cols;   
          }   
        
          public   int   getRowCount()   {   
              return   rows;   
          }   
        
          public   String   getColumnLabels(int   col)   {   
              String[]   s   =   (String[])result.firstElement();   
              return   s[col];   
          }   
        
        public   String   getCell(int   col,   int   row)   {   
            String[]   s   =   (String[])result.elementAt(row);   
            return   s[col];   
        }   
      }   
        
        
      test.jsp   
      ==============================   
      <%@   page   contentType="text/html;   charset=GBK"   %>   
      <%@   page   import="java.util.*"%>   
      <html>   
      <head>   
      <title></title>   
      <jsp:useBean   id="myMainBean"   scope="session"   class="ylb.mainBean"   />   
      <BODY   leftmargin="1"   topmargin="0">   
      <%!   
      int   rows,cols;   
      Vector   result;   
      %>   
      <%   
      result   =   myMainBean.getData();   
      rows   =   myMainBean.getRowCount();   
      cols   =   myMainBean.getColumnCount();   
      %>   
      <table   width="100%"   height="81"   border="1"   cellpadding="0"   cellspacing="0"   id=topTable>   
          <tr>   
              <td   height="79"   id=message>&nbsp;   
                                      </td>   
          </tr>   
      </table>   
      <TABLE   class=sort-table   id=mainTable   cellSpacing=1   cellPadding=4   width="100%">   
          <THEAD>   
              <TR   id="mainHead"   align="middle">   
      <%   
      for(int   i=0;i<cols;i++)   
      {   
      %>   
              <TD   noWrap><%=myMainBean.getColumnLabels(i)%></TD>   
      <%   
      }   
      %>   
              </TR>   
          </THEAD>   
          <TBODY>   
      <%   
      for(int   i=1;i<rows;i++)   
      {   
          %>   
              <TR>   
          <%   
          for(int   j=0;j<cols;j++)   
          {   
      %>   
              <TD   noWrap><%=myMainBean.getCell(j,i)%></TD>   
      <%   
          }   
      %>   
      </TR>   
      <%   
      }   
      %>   
          </TBODY>   
      </TABLE>   
        
      </body>   
      </html>   那这种是什么啊?