日期:2014-05-18  浏览次数:20784 次

JSP与ORACLE简单的问题,请前辈帮帮忙,多谢多谢!!!!!!!!!!!!!!!!!!!!!!!!!
新人刚刚接触JSP和ORACLE,给大家添麻烦了.
下面是连接数据库的JSP代码,测试后已经可以成功连接到ORACLE9I.
如果想要在浏览器中显示,我选择的字段或scott用户下emp表的全部内容.应该怎么写代码呢?
这是ORACLE9I自带的一个表,表内数据不多,请前辈帮写两句,多谢了.

<%@   page   language= "java "   import= "java.io.*,   java.sql.*,   javax.sql.* "%>  
<%@   page   import= "oracle.jdbc.*,   oracle.sql.*   "%>  


<%  
    //   Connect   to   the   database  
    Class.forName( "oracle.jdbc.driver.OracleDriver ").newInstance();      
    String   url= "jdbc:oracle:thin:@localhost:1521:myoracle ";  
   
    String   user= "scott ";  
    String   password= "zong0716 ";  
    Connection   conn=   DriverManager.getConnection(url,user,password);    


    Statement   stmt   =   conn.createStatement   ();  
    ResultSet   rs   =    
        stmt.executeQuery( "SELECT   empno(或者这里写*,选择全部字段)   FROM   scott.emp "   );  
 
    if   (rs.next())   {  
      下面不会写了:(
 
}
      //   Close   input   and   output   streams  
      is.close();  
      os.close();  
      conn.close();
%>

------解决方案--------------------
Statement stmt = conn.createStatement ();
ResultSet rs =
stmt.executeQuery( "SELECT empno(或者这里写*,选择全部字段) FROM scott.emp " );

out.println( " <table> ");
while(rs.next()) {
out.println( " <tr> ");
out.println( " <td> " + rs.getString( "第一个字段名 ") + " </td> ");
out.println( " <td> " + rs.getString( "第二个字段名 ") + " </td> ");
...

out.println( " <td> " + rs.getString( "第N个字段名 ") + " </td> ");
out.println( " </tr> ");
}
out.println( " </table> ");