这是一个个人信息管理系统的web应用程序,为本人学习完JSP后花了一天时间写的,虽然很粗糙,但因为所学知识不多,编程经验很少,能做到这样,觉得暂时还不错。数据库为sqlserver2005开发环境为eclipse以下是源代码。包括数据库的创建,B.java(JavaBeans放翁数据库),index.jsp(主页)和Jsp0.jsp,Jsp1.jsp,Jsp2.jsp,Jsp3.jsp,Jsp4.jsp,Jsp5.jsp,Jsp6.jsp,创建数据库createdatabasequanonprimary(name='quan_db',filename='d:\quan.mdf',size=5mb,maxsize=50mb,filegrowth=10%)createtablem(midchar(30)notnullprimarykey,mnamechar(10)notnull,sexchar(8),ageint,heightint,jianshuchar(50),aihaochar(50))------------------------------------------------------------------------------------------------------------------------------------------//bean访问数据库//bean访问数据库packageb;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.PreparedStatement;importjava.sql.ResultSet;importjava.sql.SQLException;publicclassB{privateStringname;privateStringmid;privateStringsex;privateintage;privateintheight;privateStringjianshu;privateStringaihao;publicvoidB(){name=;mid=;sex=;age=0;height=0;jianshu=;aihao=;}publicvoidsetName(Stringname){this.name=name;}publicStringgetName(){returnname;}publicvoidsetMid(Stringmid){this.mid=mid;}publicStringgetMid(){returnmid;}publicvoidsetSex(Stringsex){this.sex=sex;}publicStringgetSex(){returnsex;}publicvoidsetAge(intage){this.age=age;}publicintgetAge(){returnage;}publicvoidsetHeight(intheight){this.height=height;}publicfloatgetHeight(){returnheight;}publicvoidsetJianshu(Stringjianshu){this.jianshu=jianshu;}publicStringgetJianshu(){returnjianshu;}publicvoidsetAihao(Stringaihao){this.aihao=aihao;}publicStringgetAihao(){returnaihao;}static{try{Class.forName(sun.jdbc.odbc.JdbcOdbcDriver);}catch(ClassNotFoundExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}}ConnectiongetCon(Stringuser,Stringpwd){Connectioncon=null;try{con=DriverManager.getConnection(jdbc:odbc:qdb,user,pwd);}catch(SQLExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}finally{if(con==null){returnnull;}else{returncon;}}}voidclose1(Connectioncon,PreparedStatementps){try{if(con!=null)con.close();}catch(SQLExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}finally{try{if(ps!=null)ps.close();}catch(SQLExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}}}voidclose2(Connectioncon,PreparedStatementps,ResultSetrs){try{if(con!=null)con.close();}catch(SQLExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}finally{try{if(ps!=null)ps.close();}catch(SQLExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}finally{try{if(rs!=null){rs.close();}}catch(SQLExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}}}}//从数据库读取个人信息publicbooleanr(Stringmid){//一mid作为查询条件Connectioncon=null;PreparedStatementps=null;ResultSetrs=null;try{con=getCon(sa,quan1989);Stringsql=select*frommwheremid=?;ps=con.prepareStatement(sql);ps.setString(1,mid);rs=ps.executeQuery();if(rs.next()){this.mid=rs.getString(mid);this.name=rs.getString(mname);this.sex=rs.getString(sex);this.age=rs.getInt(age);this.height=rs.getInt(height);this.jianshu=rs.getString(jianshu);this.aihao=rs.getString(aihao);returntrue;}returnfalse;}catch(SQLExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();returnfalse;}finally{close2(con,ps,rs);}}//写入个人信息到数据库publicvoidw(){Connectioncon=null;PreparedStatementps=null;try{con=getCon(sa,quan1989);Stringsql=insertintomvalues(?,?,?,?,?,?,?);ps=con.prepareStatement(sql);ps.setString(1,mid);ps.setString(2,name);ps.setString(3,sex);ps.setInt(4,age);ps.setInt(5,height);ps.setString(6,jianshu);ps.setString(7,aihao);ps.executeUpdate();}catch(SQLExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}finally{close1(con,ps);}}//修改个人信息publicbooleanupdate(Stringmid){Connectioncon=null;PreparedStatementps=null;try{con=getCon(sa,quan1989);Stringsql=updatemsetmname=?,sex=?,age=?,height=?,jianshu=?,aihao=?wheremid=?;ps=con.prepareStatement(sql);ps.setString(1,name);ps.setString(2,sex);ps.setInt(3,age);ps.setInt(4,height);ps.setString(5,jianshu);ps.setString(6,aihao);ps.setString(7,mid);ps.executeUpdate();returntrue;}catch(SQLExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();returnfalse;}finally{close1(con,ps);}//暂空}publicbooleandelete(Stringmid){Connectioncon=null;PreparedStatementps=null;try{con=getCon(sa,quan1989);Stringsql=deletefrommwheremid=?;ps=con.prepareStatement(sql);ps.setString(1,mid);ps.executeUpdate();returntrue;}catch(SQLExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();returnfalse;}finally{close1(con,ps);}}}}------------------------------------------------------------------------------------------------------------------------------------------index.jsp%@pagelanguage=javaimport=java.util.*pageEncoding=gb2312%%Stringpath=request.getContextPath();StringbasePath=request.getScheme()+://+request.getServerName()+:+request.getServerPort()+path+/;%!DOCTYPEHTMLPUBLIC-//W3C//DTDHTML4.01Transitional//ENhtmlheadbasehref=%=basePath%title个人信息主页/titlemetahttp-equiv=pragmacontent=no-cachemetahttp-equiv=cache-controlcontent=no-cachemetahttp-equiv=expirescontent=0metahttp-equiv=keywo