数据库技术2016年B卷(含答案)(6)

2021-02-21 14:15

四、程序设计题(10分)

设计一个插入单位表的页面insert.jsp以及提交后的插入处理程序insert.do,并使用插入语句插入相关信息。

Insert.jsp页面仅写下form表单中的相关程序,程序不需要对表单中的信息作检查,insert.do 程序仅填写doPost中的相关程序。

单位表的名字为dept,它有两列,deptID,类型为char(2),deptName,类型为nvarchar(50) 数据库服务器地址为:exam,端口号为:8888。数据库名为dept,用户名为:sa,密码为:123,数据库驱动程序全称为:com.microsoft.sqlserver.jdbc.SQLServerDriver

insert.jsp页面代码

<body> //请填写form表单中的程序

<form action =”insert.do” method=”post” >

<label>单位编号</label> <input type="text" name=”deptId “> <br>

<label>单位名称</label> <input type="text" name=”deptName”> <br>

<button type="submit"> 插入</button>

</form>

</body>

insert.do页

public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {

request.setCharacterEncoding("UTF-8");

response.setContentType("text/html; charset=UTF-8");

try {

//请填写下方的程序段来完成插入的程序

String deptId = request.getParameter("deptId");

String deptName = request.getParameter("deptName");

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

String url ="jdbc:sqlserver://exam:8888;DatabaseName=dept";

Connection conn = DriverManager.getConnection(url,"sa","123");

Statement stmt = conn.createStatement();

String sql= " insert into dept values('"+deptId+"', '"+deptName+"' ) ";

Boolean flag= stmt.execute(sql);

stmt.close();

conn.close();

} catch (ClassNotFoundException e) {

e.printStackTrace();

} catch (SQLException e) {

e.printStackTrace();

}

}

}


数据库技术2016年B卷(含答案)(6).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:2代WiFi遥控智能小车使用说明书

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: