package test;

import java.sql.*;
import java.util.regex.Pattern; public class Data {
//getter and setter
private String hubie,housetype,houseS,home,name,id,sex,minzu,edu;
public String gethubie() {
return hubie;
}
public void sethubie(String hubie) {
this.hubie = hubie;
}
public String gethousetype() {
return housetype;
}
public void sethousetype(String housetype) {
this.housetype = housetype;
}
public String gethouseS() {
return houseS;
}
public void sethouseS(String houseS) {
this.houseS = houseS;
}
public String gethome() {
return home;
}
public void sethome(String home) {
this.home =home ;
}
public String getname() {
return name;
}
public void setname(String name) {
this.name =name ;
}
public String getid() {
return id;
}
public void setid(String id) {
this.id = id;
}
public String getsex() {
return sex;
}
public void setssex(String sex) {
this.sex = sex;
}
public String getminzu() {
return minzu;
}
public void setminzu(String minzu) {
this.minzu = minzu;
}
public String getedu() {
return edu;
}
public void setedu(String edu) {
this.edu = edu;
} //***********************************************************************
//数据库连接
public Connection getConnection()//连接数据库
{
try{
Class.forName("com.mysql.cj.jdbc.Driver");
//System.out.println("加载驱动成功");
}catch(ClassNotFoundException e)
{
e.printStackTrace();
}
String user="root";
String password="123456";
String url = "jdbc:mysql://localhost:3306/ztest01?useSSL=false&serverTimezone=GMT&characterEncoding=utf-8&autoReconnect=true";
Connection con=null;
try{
con=DriverManager.getConnection(url,user,password);
//System.out.println("数据库连接成功");
}catch(SQLException e)
{
e.printStackTrace();
} return con;
}
//**********************************************************************
//关闭方法
public void close (Connection con)
{
try{
if(con!=null)
{
con.close();
}
}catch(SQLException e)
{
e.printStackTrace();
}
}
public void close (PreparedStatement preparedStatement)
{
try{
if(preparedStatement!=null)
{
preparedStatement.close();
}
}catch(SQLException e)
{
e.printStackTrace();
}
}
public void close(ResultSet resultSet)
{
try{
if(resultSet!=null)
{
resultSet.close();
}
}catch(SQLException e)
{
e.printStackTrace();
}
}
//******************************************************************
//增
public void adddata(String hubie,String housetype,String houseS,String home,String name,String id,String sex,String minzu,String edu)
{
Connection connection = getConnection();
PreparedStatement preparedStatement=null;
try {
//hubie,housetype,houseS,home,name,id,sex,minzu,edu;
String sql = "insert into t0 (户别,住房类型,本户现住房面积,本户住房间数,户主姓名,身份证号,性别,民族,受教育程度) values (?,?,?,?,?,?,?,?,?)";
preparedStatement=connection.prepareStatement(sql);
preparedStatement.setString(1,hubie);
preparedStatement.setString(2,housetype);
preparedStatement.setString(3,houseS);
preparedStatement.setString(4,home);
preparedStatement.setString(5,name);
preparedStatement.setString(6,id);
preparedStatement.setString(7,sex);
preparedStatement.setString(8,minzu);
preparedStatement.setString(9,edu);
preparedStatement.executeUpdate();
//System.out.println("添加成功"); } catch (SQLException e) {
e.printStackTrace();
}finally{
close(preparedStatement);
close(connection);
} }
//删
public void deletedata(String id)
{
Connection connection = getConnection();
PreparedStatement preparedStatement=null;
try {
String sql = "delete from t0 where 身份证号 = ?";
preparedStatement=connection.prepareStatement(sql);
preparedStatement.setString(1,id);
preparedStatement.executeUpdate();
//System.out.println("删除成功"); } catch (SQLException e) {
e.printStackTrace();
}finally{
close(preparedStatement);
close(connection);
}
}
//改
public void revisedata(String id0, String id, String sex, String minzu , String edu)
{
Connection connection = getConnection();
PreparedStatement preparedStatement=null;
try {
//身份证号码、性别、民族、受教育程度
String sql = "update t0 set 身份证号=?, 性别=?, 民族=?, 受教育程度=? where 身份证号=?";
preparedStatement=connection.prepareStatement(sql);
preparedStatement.setString(1,id);
preparedStatement.setString(2,sex);
preparedStatement.setString(3,minzu);
preparedStatement.setString(4,edu);
preparedStatement.setString(5,id0);
preparedStatement.executeUpdate(); } catch (SQLException e) {
e.printStackTrace();
}finally{
close(preparedStatement);
close(connection);
}
} //判断方法****************************************************************
//判空
public boolean isEmpty(String hubie,String housetype,String houseS,String home,String name,String id,String sex,String minzu,String edu)
{
if(hubie==null||housetype==null||houseS==""||home==""||name==""||id==""||sex==null||minzu==""||edu=="")
return true;
else return false;
}
//判整数-面积-房间数
public boolean isNumber(String str) {
// 使用正则表达式对定义字符串的模式
Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");//^[0-9]+[0-9]*$
return pattern.matcher(str).matches();
}
//判断身份证号
public boolean isIdRight(String id)
{
if(id.length()==18)
{
for(int i=0;i<17;i++)//前17位
{
char c=id.charAt(i);
if(c=='0'||c=='1'||c=='2'||c=='3'||c=='4'||c=='5'||c=='6'||c=='7'||c=='8'||c=='9')
{continue;}
else {return false;}
}
char c=id.charAt(17);//第18位
if(c!='0'&&c!='1'&&c!='2'&&c!='3'&&c!='4'&&c!='5'&&c!='6'&&c!='7'&&c!='8'&&c!='9'&&c!='X') {
//System.out.println("不是数字或者X");
return false;
}
else {
//System.out.println("身份证号正确");
return true;
}
}
else //System.out.println("不是18位");
return false;
}
//判重/判存在
public boolean isSame(String s)
{
Connection connection = getConnection();
PreparedStatement preparedStatement=null;
ResultSet rs=null;
try {
String sql = "select * from t0";
preparedStatement=connection.prepareStatement(sql);
rs=preparedStatement.executeQuery();
while(rs.next()){
if( s.equals(rs.getObject(6))||s.equals(rs.getObject(5)) )
return true;
}
//preparedStatement.executeUpdate(); } catch (SQLException e) {
e.printStackTrace();
}finally{
close(rs);
close(preparedStatement);
close(connection);
}
return false;
} //*****************************************************************
public static void main(String[] args)
{
//test.Data a=new test.Data();
} }

实验代码Javaweb的更多相关文章

  1. [nRF51822] 12、基础实验代码解析大全 · 实验19 - PWM

    一.PWM概述: PWM(Pulse Width Modulation):脉冲宽度调制技术,通过对一系列脉冲的宽度进行调制,来等效地获得所需要波形. PWM 的几个基本概念: 1) 占空比:占空比是指 ...

  2. [nRF51822] 11、基础实验代码解析大全 · 实验16 - 内部FLASH读写

     一.实验内容: 通过串口发送单个字符到NRF51822,NRF51822 接收到字符后将其写入到FLASH 的最后一页,之后将其读出并通过串口打印出数据. 二.nRF51822芯片内部flash知识 ...

  3. [nRF51822] 10、基础实验代码解析大全 · 实验15 - RTC

    一.实验内容: 配置NRF51822 的RTC0 的TICK 频率为8Hz,COMPARE0 匹配事件触发周期为3 秒,并使能了TICK 和COMPARE0 中断. TICK 中断中驱动指示灯D1 翻 ...

  4. [nRF51822] 9、基础实验代码解析大全 · 实验12 - ADC

    一.本实验ADC 配置 分辨率:10 位. 输入通道:5,即使用输入通道AIN5 检测电位器的电压. ADC 基准电压:1.2V. 二.NRF51822 ADC 管脚分布 NRF51822 的ADC ...

  5. [nRF51822] 8、基础实验代码解析大全 · 实验11 - PPI

    前一篇分析了前十个基础实验的代码,从这里开始分析后十个~ 一.PPI原理: PPI(Programmable Peripheral Interconnect),中文翻译为可编程外设互连. 在nRF51 ...

  6. PCA降维实验代码

    实验需要提取数据的空间信息,所以要对光谱进行降维,使用主成分分析算法,样例代码备份如下 # -*- coding: utf-8 -*- """ Created on Mo ...

  7. 合肥工业大学数据结构上机实验代码与实验报告(全)github地址

    我已经将这个学期的所有数据结构上机实验的代码与报告上传到github上了,一直都有这个想法,但没抽出时间来学习git.经过上周简单的练习后,我已经基本学会运营自己的代码仓库了.所有代码都是C++写的类 ...

  8. JAVA将数字字符串强制转换成整型变量----求参数之和实验代码(附流程图)

    一.设计思想 先将参数个数输出,并利用循环结果将参数逐个输出,再将字符串强制转化成整型,利用循环结构相加求和 二.程序流程图 三.源程序代码 package demo; public class Co ...

  9. [nRF51822] 7、基础实验代码解析大全(前十)

    实验01 - GPIO输出控制LED 引脚输出配置:nrf_gpio_cfg_output(LED_1); 引脚输出置高:nrf_gpio_pin_set(LED_1); 引脚电平转换:nrf_gpi ...

  10. 实验代码:const* 和 const&

随机推荐

  1. 彻底弄懂js中this指向(包含js绑定、优先级、面试题详解)

    为什么要使用this 在javascript中,this可谓是无处不在,它可以用来指向某些元素.对象,在合适的地方使用this,能让我们减少无用代码的编写 var user = {   name: & ...

  2. 国标GB28181视频平台EasyGBS视频监控平台无法播放,抓包返回ICMP排查过程

    国标GB28181视频平台EasyGBS是基于国标GB/T28181协议的行业内安防视频流媒体能力平台,可实现的视频功能包括:实时监控直播.录像.检索与回看.语音对讲.云存储.告警.平台级联等功能.国 ...

  3. 在.NET Framework中使用RocketMQ(阿里云版)实战【第二章】

    章节 第一章:https://www.cnblogs.com/kimiliucn/p/17662052.html 第二章:https://www.cnblogs.com/kimiliucn/p/176 ...

  4. datetime去除时分秒

    datetime.datetime.now().replace(microsecond=0)

  5. CCF 202012-5星际旅行(20~100分)

    前置知识 线段树:通过懒惰标记,可实现区间处理,和区间询问皆为\(O(logn)\)时间复杂度的数据结构,是一种二叉树.因此对于一个节点\(st\),其左儿子节点为\(st*2\),右节点为\(st* ...

  6. Conda 命令深入指南

    Conda 命令深入指南 Conda 是一个功能强大的包管理系统,允许您为不同的项目创建和管理隔离的环境,从而更轻松地处理不同的依赖项集. 安装 可以按照 Conda 官方网站 (https://co ...

  7. 提高 Web 开发效率的10个VS Code扩展插件,你知道吗?

    前言 一个出色的开发工具可以显著提高开发人员的开发效率,而优秀的扩展插件则能更进一步地提升工具的效率.在前端开发领域,VSCode毫无疑问是目前最受欢迎的开发工具.为了帮助前端开发人员提高工作效率,今 ...

  8. 「codeforces - 1608F」MEX counting

    link. 首先考虑暴力,枚举规划前缀 \([1, i]\) 和前缀 mex \(x\),则我们需要 \(x\) 个数来填了 \([0, x)\),还剩下 \(i-x\) 个数随便填 \([0, x) ...

  9. Solution -「BZOJ 3779」重组病毒

    Description Link. Given is a tree. Every node initially has a color which is different from others'. ...

  10. WPF中以MVVM方式,实现RTSP视频播放

    前言视频播放在上位机开发中经常会遇到,基本上是两种常见的解决方案 1.采用厂家提供的sdk和前端控件进行展示,常见的海康/大华都提供了相关sdk及文档 2.开启相机onvif协议,捅过rtsp视频流进 ...