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. Tcpdump 使用指南

    论网络数据包的分析,我首选wireshark,因为图形化界面直观明了.但如果遇到没有图形化显示的Linux环境,那么此时会使用tcpdump该是一件多么美好的事情. 网上关于tcpdump的介绍很多, ...

  2. 使用kube-bench检测Kubernetes集群安全

    目录 一.系统环境 二.前言 三.CIS (Center for Internet Security)简介 四.什么是Kube-Bench? 五.使用kube-bench检测不安全的设置 5.1 手动 ...

  3. Ubuntu Linux 更换国内源

    Ubuntu的官方源对于国内用户来说是比较慢的,可以将它的源换成国内的源,用起来就快很多了. # Ubuntu server 环境 ubuntu@ubuntu:~$ sudo su - [ sudo ...

  4. 面霸的自我修养:ThreadLocal专题

    王有志,一个分享硬核Java技术的互金摸鱼侠 加入Java人的提桶跑路群:共同富裕的Java人 今天是<面霸的自我修养>第5篇文章,我们一起来看看面试中会问到哪些关于ThreadLocal ...

  5. c语言代码练习4

    #define _CRT_SECURE_NO_WARNINGS 1 #include <stdio.h> #include <string.h> int main() { /* ...

  6. DBeaver Ultimate 22.1.0 连接数据库(MySQL+Mongo+Clickhouse)

    前言 继续书接上文 Docker Compose V2 安装常用数据库MySQL+Mongo,部署安装好之后我本来是找了一个web端的在线连接数据库的工具,但是使用过程中并不丝滑,最终还是选择了使用 ...

  7. 其它——ZeroRPC和SimpleXMLRPCServer

    文章目录 一 Python中RPC框架 二 SimpleXMLRPCServer使用 服务端 客户端 三 ZeroRPC使用 服务端 客户端 一 Python中RPC框架 自带的:SimpleXMLR ...

  8. Android Orm框架(GreenDao)

    Android Orm框架(GreenDao) 分类: android2014-04-10 14:29 723人阅读 评论(0) 收藏 举报 GreenDao与Ormlite对比 Ormlite:简单 ...

  9. python制作定时发送信息脚本

    文章中提到的菜单是右下角这个 需求 我们需要做到打开微信获取输入框焦点及输入 思路 1,获取到右下角菜单的坐标和菜单中微信的坐标以及输入框的坐标 2,定时,用time.sleep()来定义多长时间后触 ...

  10. vue + tornado 个人博客项目简介

    vue + tornado 个人博客项目简介 项目链接:https://www.freepd.top 项目链接:https://admin.freepd.top 项目简介 首页预览 本站接入了百度ap ...