在myeclispe中使用JDBC直接访问oracle数据库
来源:互联网 发布:汕头店铺美工培训 编辑:程序博客网 时间:2024/04/28 03:45
1.新建项目
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();
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>
- 在myeclispe中使用JDBC直接访问oracle数据库
- 在Servlet中使用JDBC访问数据库
- Android通过oracle的jdbc驱动直接访问oracle数据库
- jdbc oracle数据库访问
- 在Applet中应用JDBC访问数据库
- 在JDBC中使用Oracle
- Java中使用JDBC访问MySQL数据库
- jmeter中使用jdbc访问数据库
- 在Java程序中,通过JDBC访问Oracle数据库的步骤
- 在ejb中直接利用jdbc读取数据库记录
- 使用jdbc访问数据库
- 使用jdbc访问数据库
- 使用JDBC访问数据库
- 使用JDBC访问数据库
- 使用JDBC 访问数据库
- 使用JDBC访问数据库
- Android数据库:通过JDBC直接访问MySql
- Java中使用JDBC连接oracle数据库
- CF185 div1 B. Cats Transport(单调队列斜率优化dp)
- 优化搜索结果的7个小窍门
- ios 如何隐藏各种导航栏(bar)
- ios image resize
- 精通Excel 必备3 大新技巧
- 在myeclispe中使用JDBC直接访问oracle数据库
- FreeModbus--完全分析--系列3
- POJ 1837(0-1背包)
- Eclipse中最有用的快捷键组合
- 堆和栈的区别(转过无数次的文章)
- CMWAP方式上网
- 了解您最新Gmail 邮箱
- 内容匹配广告投放技术3:网盟广告匹配(二)(百度文库课程)
- photoshop给绘制的形状使用渐变工具