http://community.csdn.net/Expert/FAQ/FAQ_Index.asp?id=69018
解决方案 »
- mybatis skserver sql
- 大家有什么好的建议?
- 那位朋友有weblogic的电子书呢?
- resin 安装为windows的服务后的问题,bug?
- 关于jotm,jdbc及clob的问题
- ibatis调用oracle存储过程返回结果集的问题
- TO 安装问题
- 我彷徨!我迷惑·
- EJB部署成功了,但在测试时初始化Home对像遇到的错误!
- 如何从数据库中读出数据,并把它写成一个文件,发送到客户机?
- QQ:13628198 看过O'reilly的Jakarta struts,学习struts的来这里讨论 Email:[email protected]
- 运行时的异常:com.mysql.jdbc.Driver
<%@ 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,在代码中如何修改呢?
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代码呢?
谢谢,我也碰到这个问题了。