在myeclispe中使用JDBC直接访问oracle数据库
2013-11-19 21:47
274 查看
1.新建项目
![](https://img-blog.csdn.net/20131119214151187?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3liZXJ6aGFvaHk=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
2.文件名称重构
![](https://img-blog.csdn.net/20131119214200765?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3liZXJ6aGFvaHk=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
![](https://img-blog.csdn.net/20131119214207281?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3liZXJ6aGFvaHk=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
3.修改编码方式,将pageEncoding修改为GB18030,以支持中文。
![](https://img-blog.csdn.net/2<br/>4000<br/>0131119214827578?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3liZXJ6aGFvaHk=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
![](https://img-blog.csdn.net/20131119214851656?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3liZXJ6aGFvaHk=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
4.添加Oracle访问类库,只需要ojdbc5.jar一个就可以了。
\\vmware-host\Shared Folders\F\待处理20130611\小软件\JAVA类库\spring类库\ojdbc5.jar
![](https://img-blog.csdn.net/20131119215031046?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3liZXJ6aGFvaHk=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
![](https://img-blog.csdn.net/20131119215054062?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3liZXJ6aGFvaHk=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
5.重新部署web程序
![](https://img-blog.csdn.net/20131119215126406?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3liZXJ6aGFvaHk=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
![](https://img-blog.csdn.net/20131119215244812?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3liZXJ6aGFvaHk=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
6.先将自动启动的tomcat服务器停止。
D:\ZhaohyInstalledSoftware\Apache Software Foundation\Tomcat 6.0\bin
![](https://img-blog.csdn.net/20131119215306312?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3liZXJ6aGFvaHk=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
![](https://img-blog.csdn.net/20131119215355968?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3liZXJ6aGFvaHk=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
7.在myeclipse中启动服务器
![](https://img-blog.csdn.net/20131119215421843?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3liZXJ6aGFvaHk=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
程序启动,使用网址测试:
http://localhost:8090/Spring_2300_Registration_1/register.jsp
![](https://img-blog.csdn.net/20131119215438328?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3liZXJ6aGFvaHk=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
8.表脚本。
-- Create table
createtable myuser
(
id numbernotnull,
username
varchar2(20)notnull,
passwordvarchar2(20)notnull
)
;
-- Create/Recreate primary, unique and foreign key constraints
altertable myuser
addconstraint idpkprimarykey
(ID);
9.代码文件:
register.jsp
<%@ pagelanguage="java"import="java.util.*"pageEncoding="GB18030"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPEHTMLPUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<basehref="<%=basePath%>">
<title>用户注册</title>
<metahttp-equiv="pragma"content="no-cache">
<metahttp-equiv="cache-control"content="no-cache">
<metahttp-equiv="expires"content="0">
<metahttp-equiv="keywords"content="keyword1,keyword2,keyword3">
<metahttp-equiv="description"content="This
is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<formmethod="post"action="registerDeal.jsp">
用户名:<inputtype="text"name="username"><br>
密码:<inputtype="password"name="password"><br>
确认密码:<inputtype="password"name="password2"><br>
<inputtype="submit"value="提交">
</form> <br>
</body>
</html>
registerDeal.jsp
<%@ pagelanguage="java"import="java.util.*,java.sql.*"pageEncoding="GB18030"%>
<%
String path = request.getContextPath
ff04
();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String username=request.getParameter("username");
String password=request.getParameter("password");
String password2=request.getParameter("password2");
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:ORCLLEAR","888888","666666");
String sqlQuery="select count(*) from myuser where username = ?";
PreparedStatement psQuery=conn.prepareStatement(sqlQuery);
psQuery.setString(1,username);
ResultSet rs=psQuery.executeQuery();
rs.next();
int count=rs.getInt(1);
if(count >0){
response.sendRedirect("registerFail.jsp");
psQuery.close();
psQuery.close();
return;
}
String sql="insert into myuser (id, username, password) values (?, ?, ?)";
PreparedStatement ps=conn.prepareStatement(sql);
ps.setInt(1,1);
ps.setString(2,username);
ps.setString(3,password);
ps.executeUpdate();
ps.close();
conn.close();
response.sendRedirect("registerSuccess.jsp");
%>
registerFail.jsp
<%@ pagelanguage="java"import="java.util.*"pageEncoding="GB18030"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPEHTMLPUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<basehref="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<metahttp-equiv="pragma"content="no-cache">
<metahttp-equiv="cache-control"content="no-cache">
<metahttp-equiv="expires"content="0">
<metahttp-equiv="keywords"content="keyword1,keyword2,keyword3">
<metahttp-equiv="description"content="This
is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
注册失败<br>
</body>
</html>
registerSuccess.jsp
<%@ pagelanguage="java"import="java.util.*"pageEncoding="GB18030"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPEHTMLPUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<basehref="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<metahttp-equiv="pragma"content="no-cache">
<metahttp-equiv="cache-control"content="no-cache">
<metahttp-equiv="expires"content="0">
<metahttp-equiv="keywords"content="keyword1,keyword2,keyword3">
<metahttp-equiv="description"content="This
is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
注册成功!<br>
</body>
</html>
2.文件名称重构
3.修改编码方式,将pageEncoding修改为GB18030,以支持中文。
4.添加Oracle访问类库,只需要ojdbc5.jar一个就可以了。
\\vmware-host\Shared Folders\F\待处理20130611\小软件\JAVA类库\spring类库\ojdbc5.jar
5.重新部署web程序
6.先将自动启动的tomcat服务器停止。
D:\ZhaohyInstalledSoftware\Apache Software Foundation\Tomcat 6.0\bin
7.在myeclipse中启动服务器
程序启动,使用网址测试:
http://localhost:8090/Spring_2300_Registration_1/register.jsp
8.表脚本。
-- Create table
createtable myuser
(
id numbernotnull,
username
varchar2(20)notnull,
passwordvarchar2(20)notnull
)
;
-- Create/Recreate primary, unique and foreign key constraints
altertable myuser
addconstraint idpkprimarykey
(ID);
9.代码文件:
register.jsp
<%@ pagelanguage="java"import="java.util.*"pageEncoding="GB18030"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPEHTMLPUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<basehref="<%=basePath%>">
<title>用户注册</title>
<metahttp-equiv="pragma"content="no-cache">
<metahttp-equiv="cache-control"content="no-cache">
<metahttp-equiv="expires"content="0">
<metahttp-equiv="keywords"content="keyword1,keyword2,keyword3">
<metahttp-equiv="description"content="This
is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<formmethod="post"action="registerDeal.jsp">
用户名:<inputtype="text"name="username"><br>
密码:<inputtype="password"name="password"><br>
确认密码:<inputtype="password"name="password2"><br>
<inputtype="submit"value="提交">
</form> <br>
</body>
</html>
registerDeal.jsp
<%@ pagelanguage="java"import="java.util.*,java.sql.*"pageEncoding="GB18030"%>
<%
String path = request.getContextPath
ff04
();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String username=request.getParameter("username");
String password=request.getParameter("password");
String password2=request.getParameter("password2");
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:ORCLLEAR","888888","666666");
String sqlQuery="select count(*) from myuser where username = ?";
PreparedStatement psQuery=conn.prepareStatement(sqlQuery);
psQuery.setString(1,username);
ResultSet rs=psQuery.executeQuery();
rs.next();
int count=rs.getInt(1);
if(count >0){
response.sendRedirect("registerFail.jsp");
psQuery.close();
psQuery.close();
return;
}
String sql="insert into myuser (id, username, password) values (?, ?, ?)";
PreparedStatement ps=conn.prepareStatement(sql);
ps.setInt(1,1);
ps.setString(2,username);
ps.setString(3,password);
ps.executeUpdate();
ps.close();
conn.close();
response.sendRedirect("registerSuccess.jsp");
%>
registerFail.jsp
<%@ pagelanguage="java"import="java.util.*"pageEncoding="GB18030"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPEHTMLPUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<basehref="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<metahttp-equiv="pragma"content="no-cache">
<metahttp-equiv="cache-control"content="no-cache">
<metahttp-equiv="expires"content="0">
<metahttp-equiv="keywords"content="keyword1,keyword2,keyword3">
<metahttp-equiv="description"content="This
is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
注册失败<br>
</body>
</html>
registerSuccess.jsp
<%@ pagelanguage="java"import="java.util.*"pageEncoding="GB18030"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPEHTMLPUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<basehref="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<metahttp-equiv="pragma"content="no-cache">
<metahttp-equiv="cache-control"content="no-cache">
<metahttp-equiv="expires"content="0">
<metahttp-equiv="keywords"content="keyword1,keyword2,keyword3">
<metahttp-equiv="description"content="This
is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
注册成功!<br>
</body>
</html>
相关文章推荐
- Android通过oracle的jdbc驱动直接访问oracle数据库
- myeclipse 使用JDBC方法直接访问sql2005
- 使用JDBC驱动程序访问Oracle数据库(实例)
- 使用低权限Oracle数据库账户得到OS访问权限
- scala 使用JDBC方式访问Mysql
- PostMan 小技巧之-直接使用 chrome 的访问
- 【TensorFlow 官网 可以直接访问】让中国开发者更容易地使用TensorFlow打造人工智能应用
- MFC中使用ADO访问Oracle数据库
- Spring学习(四)——使用Spring JDBC访问数据库
- 使用JDBC驱动程序访问数据库
- 使用!访问到具体的method中,而不是直接在xml中设置
- (转)C#连接Oracle数据库(直接引用dll使用)
- fastdfs的安装与使用,配置nginx可直接用http访问
- C#连接Oracle数据库(直接引用dll使用)
- [原创]使用VB6.0访问ORACLE数据库
- SparkSQL使用之JDBC代码访问Thrift JDBC Server
- C#中不使用Oracle Client,直接连接Oracle数据库
- Code Fragment-简单的数据类直接使用public字段来访问设值。
- 《万能数据库查询分析器》实现使用SQL语句直接高效地访问文本文件
- 使用jdbc访问数据库