http://community.csdn.net/Expert/FAQ/FAQ_Index.asp?id=69018

解决方案 »

  1.   

    感谢楼上提供的文档不过这篇文章中好像没有涉及到我上面提到的问题啊我的jsp代码(testOracle.jsp):
    <%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*"%>
    <html>
    <body>
    以下是从Oracle数据库读取的数据:<hr>
    <table border=1>
    <tr><td>id</td><td>书名</td><td>出版社</td><td>价格</td></tr>
    <%
        try
        {
        //装载Oracle驱动
        Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();    String url="jdbc:oracle:thin:@localhost:1521:oracle";
        String uid="sys";
        String pwd="liyd";    Connection con = DriverManager.getConnection(url,uid,pwd);
        Statement stmt=con.createStatement();
        ResultSet rst=stmt.executeQuery("select * from book");
        while(rst.next())
        {
        out.println("<tr>");
        out.println("<td>"+rst.getString("BOOKID")+"</td>");
        out.println("<td>"+rst.getString("bookname")+"</td>");
        out.println("<td>"+rst.getString("publisher")+"</td>");
        out.println("<td>"+rst.getFloat("price")+"</td>");
        out.println("</tr>");
        }    //关闭连接、释放资源
        rst.close();
        stmt.close();
        con.close();    }
        catch(ClassNotFoundException e)
        {
    System.out.println("Driver not found");
        }
        catch(SQLException e)
        {
         System.out.println(e.getMessage());
        }
        %>
    </table>
    </body>
    </html>在tomcat下运行后没有把book表中的记录读出来,JBuilder下显示:
    ORA-28009: connection to sys should be as sysdba or sysopersys的默认身份是normal,在代码中如何修改呢?
      

  2.   


    public class Bank {
      public static String url = "jdbc:oracle:thin:@192.168.0.98:1521:wb";
      public static String username = "system";
      public static String password = "manager";
      public Bank() {
      }
    }public class OracleJdbcBean {  private String driver; //the driver of jdbc
      private String url; //the url of database
      private String username; //the username of database
      private String password; //the password of database
      private Connection connection; //the connection to database
      private Statement statement; //the statement to execute SQL statement  public OracleJdbcBean() throws ClassNotFoundException, SQLException {
        try {
          connect(Bank.url, Bank.username, Bank.password);
        }
        catch (ClassNotFoundException e) {
          throw e;
        }
        catch (SQLException e2) {
          throw e2;
        }  }  /**
       * The beginning process of JDBC programming:
       * 1.register the driver of mysql;
       * 2.create the connection to the database of mysql;
       * 3.prepare for the execution of SQL statement.
       *
       * @throws ClassNotFoundException
       * @throws SQLException
       */  public void connect(String url, String user, String password) throws
          ClassNotFoundException, SQLException {    this.setUsername(user);
        this.setPassword(password);
        this.setUrl(url);
        this.setDriver("oracle.jdbc.driver.OracleDriver");    Connection conn = DriverManager.getConnection(this.getUrl(),
                                                      this.getUsername(),
                                                      this.getPassword());    this.setConnection(conn);
        this.setStatement(conn.createStatement());
      }  /**
       * the ending process of JDBC programming:
       * 1.while the statement is not null,close the statement;
       * 2.while the connection is not null,close the connection;
       *
       * @throws SQLException
       */
      public void disconnect() throws SQLException {
        Statement smtt = this.statement;
        Connection conn = this.getConnection();
        try {
          if (null != smtt) {
            smtt.close();
          }
          if (null != conn) {
            conn.close();
          }
        }
        catch (SQLException e) {
          System.out.println(e.getMessage());
          throw e;
        }
      }  public Statement getStatement() {
        return statement;
      }  /**
       * set the statement to execute the static SQL statement
       *
       * @param statement the statement to execute the static SQL statement
       */
      public void setStatement(Statement statement) {
        this.statement = statement;
      }  /**
       * get the driver of jdbc
       *
       * @return the driver of jdbc
       */
      public String getDriver() {
        return driver;
      }  /**
       * set the driver of jdbc
       *
       * @param driver the driver of jdbc
       */
      public void setDriver(String driver) throws ClassNotFoundException {    Class.forName(driver);
        this.driver = driver;
      }  /**
       * get the url of database
       *
       * @return the url of database
       */
      public String getUrl() {
        return url;
      }  /**
       * set the url of database
       *
       * @param url the url of database
       */
      public void setUrl(String url) {
        this.url = url;
      }  /**
       * get the connection to the database
       *
       * @return connection to the database
       */
      public Connection getConnection() {
        return connection;
      }  /**
       * set the connection to the database
       *
       * @param connection connection to the database
       */
      public void setConnection(Connection connection) {
        this.connection = connection;
      }  /**
       * get the username of database
       *
       * @return the username of database
       */
      public String getUsername() {
        return username;
      }  /**
       * set the username of database
       *
       * @param username the username of database
       */
      public void setUsername(String username) {
        this.username = username;
      }  /**
       * get the password of database according to the username
       *
       * @return the password of database according to the username
       */
      public String getPassword() {
        return password;
      }  /**
       * set the password of database according to the username
       *
       * @param password the password of database according to the username
       */
      public void setPassword(String password) {
        this.password = password;
      }  }另外一点奇怪的是
    为什么很多人都喜欢在jsp里面直接写java代码呢?
      

  3.   

    上面的问题偶自己解决了偶初学jsp,还没有习惯把类似的操作写为javaBean非常感谢dearwolf的提醒!
      

  4.   

    harri (似水年华)  ,可否说一下解决方法?
    谢谢,我也碰到这个问题了。
      

  5.   

    很抱歉,其实在代码中修改用户身份这个问题我也没有解决,我只是把用户名换成了system,不过这个用户名默认的好像不能添加表,因为我创建表的时候说权限不够,分配给他添加表的权限后就可以了。上面的测试程序也通过了。