Jsp连接Oracle 10G

Jsp连接Oracle 10G

首先第一步:

创建数据库,我这里说明一下,我用的是命令提示符创建的,想看下去的就接着来:

我的电脑----开始----运行----输入“cmd”接着就调出来了命令提示符页面

Microsoft Windows XP [版本 5.1.2600]
(C) 版权所有 1985-2001 Microsoft Corp.


C:\Documents and Settings\abin>sqlplus system/abin

SQL*Plus: Release 10.2.0.1.0 - Production on 星期四 11月 25 14:28:16 2010

Copyright (c) 1982, 2005, Oracle. All rights reserved.


连接到:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

SQL> show user;
USER 为 "SYSTEM"
SQL> conn system/abin;
已连接。
SQL> create user abing identified by abing;

用户已创建。

SQL> grant connection,resource,dba to abing identified by abing;
grant connection,resource,dba to abing identified by abing
*
第 1 行出现错误:
ORA-01919: 角色 'CONNECTION' 不存在


SQL> grant connect,resource,dba to abing identified by abing;

授权成功。

SQL> conn abing/abing;
已连接。
SQL> create table testoracle (
2 useranme varchar(50),
3 password varchar(50)
4 )
5 :
6 ;
:
*
第 5 行出现错误:
ORA-00922: 选项缺失或无效


SQL> create table testoracle (
2 useranme varchar(50),
3 password varchar(50)
4 );

表已创建。

SQL> insert into testoracle values('张山','张山家的家门钥匙在门外面的石头下面')


已创建 1 行。

SQL> insert into testoracle values('李四','李四的老婆今天不在家里面');

已创建 1 行。

SQL> commit
2 ;

提交完成。

SQL> select * from testoracle;

USERANME
--------------------------------------------------
PASSWORD
--------------------------------------------------
张山
张山家的家门钥匙在门外面的石头下面

李四
李四的老婆今天不在家里面


SQL>


第二步是,编写Jsp文件。

[img]http://dl.iteye.com/upload/picture/pic/76749/4bc67ae3-4ac1-3043-ade6-2ac91f4ab982.jpg[/img]

首先,在Myeclipse里面建立工程oracleTest,我的JSP的建立工程默认的index.jsp里面写的,内容如下:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" import="java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@localhost:1521:orcl";
//orcl为你的数据库的SID
String user="abing";
String password="abing";
Connection conn=DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select * from testoracle";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()) {%>
您的第一个字段内容为:<%=rs.getString(1)%><br><br>
您的第二个字段内容为:<%=rs.getString(2)%><br><br>
<%}%>
<%out.print("数据库操作成功,恭喜你");%>
<%rs.close();
stmt.close();
conn.close();
%>

</body>
</html>


第三步是,装载oracle 10g的驱动,ojdbc14.jar和dms.jar.

第四步是,在浏览器的地址栏输入:

http://localhost:8080/oracleTest/index.jsp


皆可查看结果。

[img]http://dl.iteye.com/upload/picture/pic/76747/b1be0c3e-5c66-3947-840f-82e02e290163.jpg[/img]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值