web数据库实验报告.docx

上传人:b****8 文档编号:30540696 上传时间:2023-08-16 格式:DOCX 页数:18 大小:285.68KB
下载 相关 举报
web数据库实验报告.docx_第1页
第1页 / 共18页
web数据库实验报告.docx_第2页
第2页 / 共18页
web数据库实验报告.docx_第3页
第3页 / 共18页
web数据库实验报告.docx_第4页
第4页 / 共18页
web数据库实验报告.docx_第5页
第5页 / 共18页
点击查看更多>>
下载资源
资源描述

web数据库实验报告.docx

《web数据库实验报告.docx》由会员分享,可在线阅读,更多相关《web数据库实验报告.docx(18页珍藏版)》请在冰豆网上搜索。

web数据库实验报告.docx

web数据库实验报告

1.答:

JDBC有四种驱动类型:

2.使用jdbc的基本过程:

3.

选择对数据库进行操作方式的界面:

查询操作的界面:

添加操作的页面:

 

删除操作的界面:

 

各个部分的代码展示:

方式界面:

fanshi.jsp:

<%@pagecontentType="text/html;charset=GB2312"%>

<%@pageimport="java.sql.*"%>

要进行的操作方式:

查询操作

删除操作

添加操作


图书数据库删除记录前的数据记录是:

<%

Stringname,number,math,english;

intphysics;

Connectioncon;

Statementsql;

ResultSetrs;

try{Class.forName("com.mysql.jdbc.Driver");

}

catch(ClassNotFoundExceptione){}

try{con=DriverManager.getConnection("jdbc:

mysql:

//localhost:

3306/pubs?

user=tanzhifei&password=tan123");

sql=con.createStatement();

rs=sql.executeQuery("SELECT*FROMbooks");

out.print("");

out.print("");

out.print(""+"书号");

out.print(""+"书名");

out.print(""+"出版社");

out.print(""+"作者");

out.print(""+"出版时间");

out.print("");

while(rs.next())

{out.print("");

number=rs.getString

(1);

out.print(""+number+"");

name=rs.getString

(2);

out.print(""+name+"");

math=rs.getString("chubanshe");

out.print(""+math+"");

english=rs.getString("zuozhe");

out.print(""+english+"");

physics=rs.getInt("date");

out.print(""+physics+"");

out.print("");

}

out.print("");

con.close();

}

catch(SQLExceptione1){}

%>

Zhuanhuan.jsp:

<%@pagecontentType="text/html;charset=GB2312"%>

<%//获取提交的操作方式:

Stringname=request.getParameter("R");

if(name==null)

{name="";}

byteb[]=name.getBytes("ISO-8859-1");

name=newString(b);

Stringpara="";

if(name.equals("查询"))

response.sendRedirect("chaxun.jsp");

if(name.equals("删除"))

response.sendRedirect("shanchu.jsp");

if(name.equals("添加"))

response.sendRedirect("tianjia.jsp");

%>

查询界面:

chaxun.jsp:

<%@pagecontentType="text/html;charset=GB2312"%>

书名查询

输入书名:

byname.jsp:

<%@pagecontentType="text/html;charset=GB2312"%>

<%@pageimport="java.sql.*"%>

<%//获取提交的书名:

Stringname=request.getParameter("name");

if(name==null)

{name="";

}

byteb[]=name.getBytes("ISO-8859-1");

name=newString(b);

Connectioncon=null;

Statementsql=null;

ResultSetrs=null;

try{Class.forName("com.mysql.jdbc.Driver");

}

catch(ClassNotFoundExceptione){}

try{con=DriverManager.getConnection("jdbc:

mysql:

//localhost:

3306/pubs?

user=tanzhifei&password=tan123");

sql=con.createStatement();

Stringcondition=

"SELECT*FROMbooksWHEREshuming="+"'"+name+"'";

rs=sql.executeQuery(condition);

out.print("");

out.print("");

out.print(""+"书号");

out.print(""+"书名");

out.print(""+"出版社");

out.print(""+"作者");

out.print(""+"出版时间");

out.print("");

while(rs.next())

{out.print("");

out.print(""+rs.getInt("shuhao")+"");

out.print(""+rs.getString("shuming")+"");

out.print(""+rs.getString("chubanshe")+"");

out.print(""+rs.getString("zuozhe")+"");

out.print(""+rs.getInt("date")+"");

out.print("");

}

out.print("");

con.close();

}

catch(SQLExceptione)

{}

%>

单击此超链接,可到操作方式选择页面

返回

添加操作的界面:

tianjia.jsp:

<%@pagecontentType="text/html;charset=GB2312"%>

<%@pageimport="java.sql.*"%>

添加新的记录到数据库:

图书书号:


图书书名:


出版社:


作者:


出版日期:


数据库添加记录前的数据记录是:

<%

Stringname,number,math,english;

intphysics;

Connectioncon;

Statementsql;

ResultSetrs;

try{Class.forName("com.mysql.jdbc.Driver");

}

catch(ClassNotFoundExceptione){}

try{con=DriverManager.getConnection("jdbc:

mysql:

//localhost:

3306/pubs?

user=tanzhifei&password=tan123");

sql=con.createStatement();

rs=sql.executeQuery("SELECT*FROMbooks");

out.print("");

out.print("");

out.print(""+"书号");

out.print(""+"书名");

out.print(""+"出版社");

out.print(""+"作者");

out.print(""+"出版时间");

out.print("");

while(rs.next())

{out.print("");

number=rs.getString

(1);

out.print(""+number+"");

name=rs.getString

(2);

out.print(""+name+"");

math=rs.getString("chubanshe");

out.print(""+math+"");

english=rs.getString("zuozhe");

out.print(""+english+"");

physics=rs.getInt("date");

out.print(""+physics+"");

out.print("");

}

out.print("");

con.close();

}

catch(SQLExceptione1){}

%>

单击此超链接,可到操作方式选择页面

返回

newDatabase.jsp:

<%@pagecontentType="text/html;charset=GB2312"%>

<%@pageimport="java.sql.*"%>

<%//获取提交的书号:

Stringnumber=request.getParameter("number");

if(number==null)

{number="";}

byteb[]=number.getBytes("ISO-8859-1");

number=newString(b);

//获取提交的书名:

Stringname=request.getParameter("name");

if(name==null)

{name="";

}

bytea[]=name.getBytes("ISO-8859-1");

name=newString(a);

Stringc=request.getParameter("chubanshe");

if(c==null)

{c="";

}

byted[]=c.getBytes("ISO-8859-1");

c=newString(d);

Stringw=request.getParameter("zuozhe");

if(w==null)

{w="";

}

bytee[]=w.getBytes("ISO-8859-1");

w=newString(e);

Strings=request.getParameter("date");

if(s==null)

{s="0";}

Connectioncon=null;

Statementsql=null;

ResultSetrs=null;

try{Class.forName("com.mysql.jdbc.Driver");}

catch(ClassNotFoundExceptionevent){}

try{con=DriverManager.getConnection("jdbc:

mysql:

//localhost:

3306/pubs?

user=tanzhifei&password=tan123");

sql=con.createStatement();

Stringcondition="INSERTINTObooksVALUES"+"("+"'"+number+"','"+name+"','"+c+"','"+w+"',"+s+")";

sql.executeUpdate(condition);//执行添加操作:

//显示添加新记录后表中的记录:

%>

添加新记录后的表:

<%

rs=sql.executeQuery("SELECT*FROMbooksORDERBYshuhao");

out.print("");

out.print("");

out.print(""+"书号");

out.print(""+"书名");

out.print(""+"出版社");

out.print(""+"作者");

out.print(""+"出版时间");

out.print("");

while(rs.next())

{out.print("");

Stringn=rs.getString("shuhao");

out.print(""+n+"");

Stringshuming=rs.getString("shuming");

out.print(""+shuming+"");

Stringmath=rs.getString("chubanshe");

out.print(""+math+"");

Stringenglish=rs.getString("zuozhe");

out.print(""+english+"");

intphysics=rs.getInt("date");

out.print(""+physics+"");

out.print("");

}

out.print("");

con.close();

}

catch(SQLExceptionevent)

{out.print(""+event);

}

%>

单击此超链接,可到操作方式选择页面

返回

删除操作:

Shanchu.jsp:

<%@pagecontentType="text/html;charset=GB2312"%>

<%@pageimport="java.sql.*"%>

删除操作

输入要删除的书号:

图书数据库删除记录前的数据记录是:

<%

Stringname,number,math,english;

intphysics;

Connectioncon;

Statementsql;

ResultSetrs;

try{Class.forName("com.mysql.jdbc.Driver");

}

catch(ClassNotFoundExceptione){}

try{con=DriverManager.getConnection("jdbc:

mysql:

//localhost:

3306/pubs?

user=tanzhifei&password=tan123");

sql=con.createStatement();

rs=sql.executeQuery("SELECT*FROMbooks");

out.print("");

out.print("");

out.print(""+"书号");

out.print(""+"书名");

out.print(""+"出版社");

out.print(""+"作者");

out.print(""+"出版时间");

out.print("");

while(rs.next())

{out.print("");

number=rs.getString

(1);

out.print(""+number+"");

name=rs.getString

(2);

out.print(""+name+"");

math=rs.getString("chubanshe");

out.print(""+math+"");

english=rs.getString("zuozhe");

out.print(""+english+"");

physics=rs.getInt("date");

out.print(""+physics+"");

out.print("");

}

out.print("");

con.close();

}

catch(SQLExceptione1){}

%>

单击此超链接,可到操作方式选择页面

返回

delete.jsp:

<%@pagecontentType="text/html;charset=GB2312"%>

<%@pageimport="java.sql.*"%>

<%//获取提交的书号:

Stringnumber=request.getParameter("number");

if(number==null)

{number="";

}

byteb[]=number.getBytes("ISO-8859-1");

number=newString(b);

Connectioncon=null;

Statementsql=null;

ResultSetrs=null;

try{Class.forName("com.mysql.jdbc.Driver");

}

catch(ClassNotFoundExceptionevent){}

try{con=DriverManager.getConnection("jdbc:

mysql:

//localhost:

3306/pubs?

user=tanzhifei&password=tan123");

sql=con.createStatement();

//删除操作:

StringdeleteAll="DELETEFROMbooksWHEREshuhao"+"="+"'"+number+"'";

sql.exec

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 考试认证 > IT认证

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1