2023年11月28日发(作者:)
仅用Jsp实现对数据库的增删改查
首先,打开sql*plus,输入用户名(我用的scott)密码(我设置的是tiger)。
先建个表student,
Create table student (
id number(30) not null primary key,
name varchar(50) ,
age number(30),
gender varchar(30),
major varchar(50) );
1,打开myeclipse8.5新建一个web project
2,在project name 中输入合法名字,比如normal
3,新建的normal工程
4,在webRoot目录下添加以下.jsp文件
4.1 文件
代码如下:
<%@ page language="java" import=".*" pageEncoding="UTF-8"%>
<%
String path = textPath();
String basePath =
eme()+"://"+verName()+":"+verPort()+path+"/";
%>
<%
racterEncoding("UTF-8");
racterEncoding("UTF-8");
%>
学生信息
全部学生信息如下
<% while(()) { (" (" (" (" (" (" %> <% (" } %>
学号 姓名 年龄 性别 专业 "); "); "+("id")+" "); "+ing("name")+" "); "+("age")+" "); "+ing("gender")+" "); "+ing("major")+" "); ">删除 ">修改
按学号查询: value="" title="学号不能为空" > 按姓名查询: "> "> <% if(rs!=null) { (); } if(stat!=null) { (); } if(conn!=null) { (); } %> 4.4 文件 <%@ page language="java" import=".*" pageEncoding="UTF-8"%> <%@ page import=".*"%> <% String path = textPath(); String basePath = eme()+"://"+verName()+":"+verPort()+path+"/"; %> <% racterEncoding("UTF-8"); String id=ameter("id"); // String name=ameter("name"); // String age=ameter("age"); // String gender=ameter("gender"); // String major=ameter("major"); Connection conn=null; Statement stat=null; (" } %> 面 <% if(rs!=null) { (); } if(stat!=null) { (); } if(conn!=null) { (); } %> 4.5 文件 <%@ page language="java" import=".*" pageEncoding="UTF-8"%> <%@ page import=".*"%> <% String path = textPath(); String basePath = eme()+"://"+verName()+":"+verPort()+path+"/"; %> <% racterEncoding("UTF-8"); String id=ameter("id"); Connection conn=null; Statement stat=null; ResultSet rs=null; e("Driver"); String url="jdbc:oracle:thin:@localhost:1521:orcl"; String user="scott"; String password="tiger"; conn=nection(url,user,password); stat=Statement(); rs=eQuery("select * from student where id="+id+""); %> 符合条件的学生信息 <% if(()) { (" <% (" } else{ ("不存在此条件的信息!"); } %> <% if(rs!=null) { (); } if(stat!=null) { (); } if(conn!=null) { (); } <% racterEncoding("UTF-8"); String name=ameter("name"); Connection conn=null; Statement stat=null; ResultSet rs=null; e("Driver"); String url="jdbc:oracle:thin:@localhost:1521:orcl"; String user="scott"; String password="tiger"; conn=nection(url,user,password); stat=Statement(); rs=eQuery("select * from student where name='"+name+"'"); %> 符合条件的学生信息 (" (" (" %> <% (" } else{ ("不存在此条件的信息!"); } %> <% if(rs!=null) { (); } if(stat!=null) { (); } if(conn!=null) { (); } %>
按年龄查询:
按性别查询:type="text" name="gender" value=""title="性别不能为空
按专业查询:type="text" name="major" value=""title="专业不能为空
学号 姓名 年龄 性别 专业 "); ");
"); 学号 姓名 年龄 性别 专业 "+("age")+" "); "+ing("gender")+" "); "+ing("major")+" "); ">删除 ">修改
