- 4
- 0
- 约 8页
- 2016-10-23 发布于湖北
- 举报
学号 姓名 实验序号 实验十二 实验名称 数据库编程 实验地点 实验日期 实验内容 1.在数据库(xscj)里建立如下数据表tb_student:
使用的数据库系统不限。
2.使用Java JDBC对该数据表进行增删改查,输出到屏幕。JDBC连接方式不限。
(1)从键盘输入数据并能写入数据表中
(2)修改学生成绩
(3)删除指定学号的数据
(4)按学生姓名模糊查询
实验过程及步骤 在SQL数据库中创建xscj数据库,建立数据表tb_student。
使用Java JDBC对该数据表进行增删改查,输出到屏幕。
一:BaseDao:
package com.util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
public class BaseDao {
protected Connection conn=null;
protected Statement stmt=null;
protected PreparedStatement pstmt=null;
protected ResultSet rs=null;
public Connection getConn(){
Connection aconn=null;
try{
Class.forName
(com.microsoft.sqlserver.jdbc.SQLServerDriver);
aconn=DriverManager.getConnection
实验过程及步骤 (jdbc:sqlserver://localhost:1433;DatabaseName=xscj,sa,123456);
}catch(Exception ex){
ex.printStackTrace();
}
return aconn;
}
public void closeAll(){
try{
if(rs!=null)rs.close();
if(pstmt!=null)pstmt.close();
if(stmt!=null)stmt.close();
if(conn!=null)conn.close();
}catch(Exception ex){
ex.printStackTrace();
}}}
二:StudentDao
package com.dao;
import java.util.List;
import com.bean.Student;
public interface StudentDao {
public int insert(Student stu);
public int deletestudent(int stuno);
public ListStudent getStudentByName(String stuname);
public int modify(Student stu);
}
三:StudentDaoImpl
package com.dao.impl;
import java.util.ArrayList;
import java.util.List;
import com.bean.Student;
import com.dao.StudentDao;
import com.util.BaseDao;
public class StudentDaoImpl extends BaseDao implements StudentDao {
public int insert(Student stu) {
int row = 0;
try {
conn = this.getConn();
String sql = insert into tb_student(stuno,stuname,stuscore) values(?,?,?); 实验过程及步骤 pstmt = conn.prepareStatement(sql);
pstmt.setInt(1, stu.getStuNo());
pstmt.setString(2, stu.getStuname());
pstmt.setInt(3, stu.getStuscore());
row = pstmt.executeUpdate();
} catch (Exception e
您可能关注的文档
- 2016注册监理工程师继续教育房建专业考及及答案.doc
- A02-TS16949-FMEA培训(教)及答案.doc
- BonusWorkshopManual02CN及答案.doc
- C语言链表的排序及答案.doc
- EDA实验报告及答案.doc
- ERP笔记整理2及答案.doc
- EXCEL函数大全及答案.doc
- G2SW选修3第三章胚胎工程导及答案.doc
- GCH系列低压开关柜任务及答案.doc
- GMAT_核心词汇List_16-30及答案.doc
- 广东省广州省实验中学教育集团2025-2026学年八年级上学期期中考试物理试题(解析版).docx
- 广东省广州大学附属中学2025-2026学年八年级上学期奥班期中物理试题(解析版).docx
- 广东省广州市第八十六中学2025-2026学年八年级上学期期中物理试题(含答案).docx
- 广东省广州市第八十九中学2025-2026学年八年级上学期期中考试物理试题(解析版).docx
- 广东省广州市第二中学2025-2026学年八年级上学期期中考试物理试题(含答案).docx
- 广东省广州市第八十六中学2025-2026学年八年级上学期期中物理试题(解析版).docx
- 广东省广州市第八十九中学2025-2026学年八年级上学期期中考试物理试题(含答案).docx
- 广东省广州市第二中学2025-2026学年八年级上学期期中考试物理试题(解析版).docx
- 2026《中国人寿上海分公司营销员培训体系优化研究》18000字.docx
- 《生物探究性实验教学》中小学教师资格模拟试题.docx
原创力文档

文档评论(0)