Jsp中调用Oracle存储过程的小例子(转)
http://www.cnjsp.org/view.jsp?column=2&id=576
Jsp中调用Oracle存储过程的小例子
发布日期:2002-04-05 作者: yanchang(笨笨) 阅读人次:9998

以下的例子转自csdn论坛:

*执行一条insert语句并传参数*/
create or replace procedure p_test2(i in number) as
begin
insert into t values (i,'x'||to_char(i));
commit;
end;
/

<%@ page language="java" contentType="text/html;charset=gb2312"%>
<%@page import=
"java.sql.*"%>
<html>
<body>
<table>
<tr><td>aaa</td><td>bbb</td></tr>
<%
String driver =
"oracle.jdbc.driver.OracleDriver";
String strUrl =
"jdbc:oracle:thin:@192.168.1.6:1521:db";

Class.forName(driver);
Connection conn = DriverManager.getConnection(strUrl,
"scott", "tiger");

String procedure =
"{call p_test2 (?) }";
CallableStatement cstmt = conn.prepareCall(procedure);
cstmt.setInt(1,33);
cstmt.executeUpdate();

Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(
"select * from t");

while(rs.next())
{
out.println(
"<tr><td>" + rs.getString(1) + "</td><td>" + rs.getString(2) + "</td></tr>");
}

rs.close();
stmt.close();
conn.close();
%>
</table>
<p>
<%
out.print(conn.isClosed());
%>

</body>
</html>
</body>
</html>


------

回复此文章 |

如果数据库是MySql 下面那行代码应该怎么写??:

String driver = "oracle.jdbc.driver.OracleDriver";

查资料是这样写的:
String mysqlDriver="org.gjt.mm.mysql.Driver";
------
回复此文章 |

String driver = "oracle.jdbc.driver.OracleDriver";
String strUrl = "jdbc:oracle:thin:@192.168.1.6:1521:db";

改为:
String url="jdbc:mysql://192.168.0.1:3306/joke?user=mis&password=miss";
String driver = com.mysql.jdbc.Driver
大概是这样吧!



hofman   2005-11-19 22:29:35 评论:0   阅读:2267   引用:0

发表评论>>

署名发表(评论可管理,不必输入下面的姓名)

姓名:

主题:

内容: 最少15个,最长1000个字符

验证码: (如不清楚,请刷新)

Copyright@2004-2010 powered by YuLog