学生管理jsp学生信息的增删改查查

学生管理系统增删改查_百度文库
您的浏览器Javascript被禁用,需开启后体验完整功能,
享专业文档下载特权
&赠共享文档下载特权
&100W篇文档免费专享
&每天抽奖多种福利
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
学生管理系统增删改查
&&学生管理系统增删改查
你可能喜欢1.Dao.java
//连接数据库
package com.stu.
import java.sql.*;
public class Dao {
private static C//定义一个静态连接类型对象
public static Connection getConn(){
Class.forName("com.mysql.jdbc.Driver");//加载驱动
connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/studb","root","");//得到数据库链接对象并且给connection赋值
} catch (Exception e) {
e.printStackTrace();
public static void closeAll(ResultSet res,PreparedStatement smt,Connection conn){
if(res!=null){
res.close();
if(smt!=null){
smt.close();
if(conn!=null){
conn.close();
}catch(Exception e){
2.Student.java
//定义Student类型
package com.stu.
public class Student {
//javabean
//private不能被外部直接访问,每个属性都有一个get和set方法用来读取或设置私有属性的值
public Integer getId() {
public void setId(Integer id) {
public String getStuname() {
public void setStuname(String stuname) {
this.stuname =
public String getStuage() {
public void setStuage(String stuage) {
this.stuage =
public String getStusex() {
public void setStusex(String stusex) {
this.stusex =
public Student(Integer id, String stuname, String stuage, String stusex) {//构造方法:实例化对象时直接赋值
this.stuname =
this.stuage =
this.stusex =
public Student(){
3.StudentDao()
package com.stu.
import java.sql.C
import java.sql.PreparedS
import java.sql.ResultS
import java.sql.SQLE
import java.util.ArrayL
import java.util.L
public class StudentDao {
private List&Student&
private PreparedS
private ResultS
public List&Student& getAll(){
stus=new ArrayList&Student&();
conn= Dao.getconn();
smt=conn.prepareStatement("select * from stu_tab");
rs=smt.executeQuery();
while(rs.next()){
Student student=new Student(rs.getInt("id"),rs.getString("stuname"),rs.getString("stuage"),rs.getString("stusex"));
stus.add(student);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
new Dao().closeAll(rs, smt, conn);
public void delete(int id){
conn= Dao.getconn();
smt=conn.prepareStatement("delete from stu_tab where id=?");
smt.setInt(1, id);
smt.execute();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
new Dao().closeAll(rs, smt, conn);
public void insert(Student student){
conn= Dao.getconn();
smt=conn.prepareStatement("insert into stu_tab (stuname,stuage,stusex)values(?,?,?)");
smt.setString(1, student.getStuname());
smt.setString(2, student.getStuage());
smt.setString(3, student.getStusex());
smt.execute();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
new Dao().closeAll(rs, smt, conn);
public Student ById(Integer id){
Student val =
conn=Dao.getconn();
smt=conn.prepareStatement("select * from stu_tab where id=?");
smt.setInt(1, id);
rs=smt.executeQuery();
while(rs.next()){
val=new Student(rs.getInt("id"),rs.getString("stuname"),rs.getString("stuage"),rs.getString("stusex"));
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
new Dao().closeAll(rs, smt, conn);
public void update(Student stu){
conn= Dao.getconn();
smt=conn.prepareStatement("update stu_tab set stuname=?,stuage=?,stusex=? where id=?");
smt.setString(1, stu.getStuname());
smt.setString(2, stu.getStuage());
smt.setString(3, stu.getStusex());
smt.setInt(4,stu.getId());
smt.execute();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
new Dao().closeAll(rs, smt, conn);
4.StudentServlet.java
package com.stu.
import java.io.IOE
import java.util.ArrayL
import javax.servlet.ServletE
import javax.servlet.annotation.WebS
import javax.servlet.http.HttpS
import javax.servlet.http.HttpServletR
import javax.servlet.http.HttpServletR
@WebServlet("/studentservlet")
public class StudentServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doPost(request, response);
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String method=request.getParameter("method");
if(method.equals("all")){
this.all(request, response);
if(method.equals("delete")){
this.delete(request,response);
if(method.equals("insert")){
this.insert(request,response);
if(method.equals("update1")){
this.update1(request,response);
if(method.equals("update2")){
this.update2(request,response);
private void update2(HttpServletRequest request,
HttpServletResponse response) throws IOException {
Integer id=Integer.parseInt(request.getParameter("id"));
String stuname=request.getParameter("stuname");
String stuage=request.getParameter("stuage");
String stusex=request.getParameter("stusex");
new StudentDao().update(new Student(id,stuname,stuage,stusex));
response.sendRedirect("studentservlet?method=all");
private void update1(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
Integer id=Integer.parseInt(request.getParameter("id"));
Student stu=new StudentDao().ById(id);
request.setAttribute("stus", stu);
request.getRequestDispatcher("/update.jsp").forward(request, response);
private void delete(HttpServletRequest request, HttpServletResponse response) throws IOException {
Integer id=Integer.parseInt(request.getParameter("id"));//从show页面接收id的值
new StudentDao().delete(id);
response.sendRedirect("studentservlet?method=all");
public void all(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
ArrayList al=(ArrayList) new StudentDao().getAll();//调用getall()方法
request.setAttribute("all",al);//将值放入Request
request.getRequestDispatcher("/show.jsp").forward(request, response);//请求转发到指定页面
public void insert(HttpServletRequest request, HttpServletResponse response) throws IOException{
String stuname=request.getParameter("stuname");
String stuage=request.getParameter("stuage");
String stusex=request.getParameter("stusex");
new StudentDao().insert(new Student(0,stuname,stuage,stusex));
response.sendRedirect("studentservlet?method=all");
5.show.jsp
&%@page import="com.stu.test.Student"%&
&%@page import="java.util.ArrayList"%&
&%@ page language="java" contentType="text/ charset=UTF-8"
pageEncoding="UTF-8"%&
&!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&
&meta http-equiv="Content-Type" content="text/ charset=UTF-8"&
&title&Insert title here&/title&
ArrayList&Student& list=(ArrayList&Student&)request.getAttribute("all");//
&h1&&a href="insert.jsp"&insert&/a&&/h1&
&table border=1&
&td&id&/td&
&td&username&/td&
&td&userage&/td&
&td&usersex&/td&
&td&操作&/td&
&%for(Student lists:list){%&
&td&&%=lists.getId()%&&/td&
&td&&%=lists.getStuname()%&&/td&
&td&&%=lists.getStuage()%&&/td&
&td&&%=lists.getStusex()%&&/td&
&a href="studentservlet?method=delete&id=&%=lists.getId()%&"&删除&/a&
&a href="studentservlet?method=update1&id=&%=lists.getId()%&"&修改&/a&
6.insert.jsp
&!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&
&meta http-equiv="Content-Type" content="text/ charset=UTF-8"&
&title&Insert title here&/title&
&form method="post" action="studentservlet?method=insert"&
stuname:&input type="text" name="stuname" &&br&
stuname:&input type="text" name="stuage" &&br&
stuname:&input type="text" name="stusex" &&br&
&input type="submit" name="sub" value="tijiao"&
7.updata.jsp
&%@page import="com.stu.test.Student"%&
&%@ page language="java" contentType="text/ charset=UTF-8"
pageEncoding="UTF-8"%&
&!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&
&meta http-equiv="Content-Type" content="text/ charset=UTF-8"&
&title&Insert title here&/title&
&%Student val=(Student)request.getAttribute("stus"); %&
&form method="post" action="studentservlet?method=update2"&
&input type="hidden" name="id" value=&%=val.getId() %& &
stuname:&input type="text" name="stuname" value=&%=val.getStuname() %&&&br&
stuname:&input type="text" name="stuage" value=&%=val.getStuage() %&&&br&
stuname:&input type="text" name="stusex" value=&%=val.getStusex() %&&&br&
&input type="submit" name="sub" value="tijiao"&
8.index.jsp
&%@ page language="java" contentType="text/ charset=UTF-8"
pageEncoding="UTF-8"%&
&!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&
&meta http-equiv="Content-Type" content="text/ charset=UTF-8"&
&title&Insert title here&/title&
&a href="studentservlet?method=all"&show&/a&
java对象数组的增删练习之《学生信息管理系统》
java 利用数组实现增删改查
学生管理系统(增删改查)
学生管理系统--实现了系统的增删改查~
没有更多推荐了,博客分类:
&&& 刚开始,我用eclipse编写的,编译器使用的是gcc,然后把代码拷贝到vs2010上,很多代码都通过不了,后来有改了下,可以再vs上跑。感觉C语言的很多编译器差别很大,编译器之间的可移植性真的不好,而且我感觉C程序还得看在什么操作系统上跑,不同的操作系统,C的类库不太一样,在windows使用vs可以最大的编写出强大的程序;在linux使用gcc也更大的编写更好的程序,但是系统之间C程序的移植就另说了。
&&& 一个值得注意的问题,window下换行符号'\n'在文件中是两个字节的存储,而在内存中又是一个字节的存储,两者之间的转换有点麻烦,所以我避开了换行符,使用回车符存储。
下载次数: 8
浏览: 54782 次
来自: 北京
(window.slotbydup=window.slotbydup || []).push({
id: '4773203',
container: s,
size: '200,200',
display: 'inlay-fix'JDBC应用、控制台连MySQL接数据库实现学生管理系统的登录注册、增删改查
时间: 11:43:26
&&&& 阅读:1067
&&&& 评论:
&&&& 收藏:0
标签:**=====================连接数据库=====================**package com.sore.import java.sql.*;public class Jdbc {static Connection conn= //创建连接桥& & public static void main(String[] args) {try{Class.forName("com.mysql.jdbc.Driver"); //加载驱动String url="jdbc:mysql://localhost:3306/user";//数据库查询地址及协议String name="root";//连接数据库账户名String pwd="root";//连接数据库密码conn=DriverManager.getConnection(url,name,pwd);//加载数据库管理资源System.out.println("connection success !");}catch(Exception e){e.printStackTrace();}finally{ & &//关闭数据库资源try{if(conn!=null){conn.close();}}catch(Exception e){e.printStackTrace();}}}}**=====eclipse控制台的学生管理系统(登录注册、增删改查)====**package com.sore.import java.sql.*;import java.util.Spublic class Jdbc { static Connection conn= //创建连接桥 static PreparedStatement ps= //预编译sql语句 static ResultSet rs= //得到数据库查询结果集 public static void main(String[] args) {
getConn(); &//调用数据库连接类
regist(); & //调用登录注册类 } public static Connection getConn(){ //连接数据库方法
Class.forName("com.mysql.jdbc.Driver"); //加载驱动
String url="jdbc:mysql://localhost:3306/user";//数据库查询地址及协议
String name="root";//连接数据库账户名
String pwd="root";//连接数据库密码
conn=DriverManager.getConnection(url,name,pwd);//加载数据库管理资源
System.out.println("connection success !");
}catch(Exception e){
e.printStackTrace();
} public static void regist(){ //登录注册类
Scanner sc=new Scanner(System.in);
while(true){
System.out.println("请输入您的登录用户名:");
String name=sc.next();
System.out.println("请输入您的登录密码:");
String pwd=sc.next();
String sql="select*from user_login where name=? and pwd=?";
ps=conn.prepareStatement(sql);
ps.setString(1, name);
ps.setString(2, pwd);
rs=ps.executeQuery();//得到查询结果
if(rs.next()){
while(true){
System.out.println("success,请输入您的操作选项:1.增加用户;2.删除用户;3.修改用户;4.查找用户;5.退出系统");
int input=sc.nextInt();
switch(input){
case 1://增
System.out.println("请输入您添加的用户名:");
String name_add=sc.next();
System.out.println("请输入您要添加的密码:");
String pwd_add=sc.next();
String sql_s="select*from user_login where name=? and pwd=?";
ps=conn.prepareStatement(sql_s);
ps.setString(1, name_add);
ps.setString(2, pwd_add);
rs=ps.executeQuery();
if(rs.next()){
System.out.println("添加失败,该用户已存在");
String sql_add="insert into user_login(name,pwd)values(?,?)";
ps=conn.prepareStatement(sql_add);
ps.setString(1, name_add);
ps.setString(2,pwd_add);
ps.executeUpdate();
System.out.println("添加成功");
case 2://删
System.out.println("请输入您要删除的用户id:");
String id_de=sc.next();
String sql_de="select*from user_login where id=?";
ps=conn.prepareStatement(sql_de);
ps.setString(1, id_de);
rs=ps.executeQuery();
if(rs.next()){
String sql_del="delete from user_login where id=?";
ps=conn.prepareStatement(sql_del);
ps.setString(1, id_de);
ps.executeUpdate();
System.out.println("删除成功");
case 3://改
System.out.println("请输入您要修改的选项:1.用户名;2.密码");
String chose=sc.next();
if(chose.equals("1")){//修改用户名
System.out.println("输入您要修改的id:");
String id_u=sc.next();
String sql_u="select*from user_login where id=?";
ps=conn.prepareStatement(sql_u);
ps.setString(1, id_u);
rs=ps.executeQuery();
if(rs.next()){
System.out.println("用户存在,请输入您要修改后的用户名:");
String name_up=sc.next();
String sql_up="update user_login set name=? where id=?";
ps=conn.prepareStatement(sql_up);
ps.setString(1, name_up);
ps.setString(2, id_u);
ps.executeUpdate();
System.out.println("修改成功");
}else if(chose.equals("2")){//修改密码
System.out.println("请输入您要修改的id号:");
String id=sc.next();
String sql_i="select*from user_login where id=?";
ps=conn.prepareStatement(sql_i);
ps.setString(1, id);
rs=ps.executeQuery();
if(rs.next()){
System.out.println("该用户存在,请输入您要修改的密码:");
String pwd_i=sc.next();
String sql_id="update user_login set pwd=? where id=?";
ps=conn.prepareStatement(sql_id);
ps.setString(1, pwd_i);
ps.setString(2, id);
ps.executeUpdate();
System.out.println("修改成功");
case 4://查
System.out.println("请输入您要查看的用户id:");
String id_s=sc.next();
String sql_se="select*from user_login where id=?";
ps=conn.prepareStatement(sql_se);
ps.setString(1, id_s);
rs=ps.executeQuery();
if(rs.next()){
System.out.println("该用户存在,其信息为:");
System.out.println("id:"+rs.getString(1)+"name:"+rs.getString(2)+"pwd:"+rs.getString(3));
System.out.println("该用户不存在");
System.out.println("see you");
System.exit(0);
System.out.println("该用户不存在,请注册:");
System.out.println("请输入用户名:");
String name_zc=sc.next();
System.out.println("请输入密码:");
String pwd_zc=sc.next();
String sql_cx="select*from user_login where name=? and pwd=?";
ps=conn.prepareStatement(sql_cx);
ps.setString(1, name_zc);
ps.setString(2, pwd_zc);
rs=ps.executeQuery();
if(rs.next()){
System.out.println("该用户已存在");
String sql_zc="insert into user_login(name,pwd)values(?,?)";
ps=conn.prepareStatement(sql_zc);
ps.setString(1, name_zc);
ps.setString(2, pwd_zc);
ps.executeUpdate();
System.out.println("注册成功");
}catch(Exception e){
e.printStackTrace();
if(rs!=null){
rs.close();
}else if(ps!=null){
ps.close();
}else if(conn!=null){
conn.close();
}catch(Exception e){
e.printStackTrace();
} }}本文出自 “” 博客,谢绝转载!标签:原文地址:http://sorewzx.blog.51cto.com/9105
&&国之画&&&& &&&&chrome插件
版权所有 京ICP备号-2
迷上了代码!求学生成绩管理系统!要求:能实现查询,添加、修改学生信息,能实现对课程的查询、添加、删除、修改。能_百度知道
求学生成绩管理系统!要求:能实现查询,添加、修改学生信息,能实现对课程的查询、添加、删除、修改。能
求学生成绩管理系统!要求:能实现查询,添加、修改学生信息,能实现对课程的查询、添加、删除、修改。能实现成绩的录入、查询、和修改。...
求学生成绩管理系统!要求:能实现查询,添加、修改学生信息,能实现对课程的查询、添加、删除、修改。能实现成绩的录入、查询、和修改。
答题抽奖
首次认真答题后
即可获得3次抽奖机会,100%中奖。
IT类认证行家
采纳数:10978
获赞数:20000
已经做过两个上架的app和两个网页项目.
java 的学生管理系统,这是一个很基础的项目,csdn网站下载的频道已经有很多人上传过该资源,主要是通过java swing和mysql技术实现的。数据库的增删改查,其实在是通过jdbc连接mysql数据库来处理,首先理清成绩管理系统各个表之间的关系,然后新建表,保存数据。
我要的是葫芦
茎叶我已经养好了
执行时出了问题
为你推荐:
其他类似问题
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。}

我要回帖

更多关于 学生信息增删改查jsp 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信