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. cesium中限制地图浏览范围

    https://blog.csdn.net/qq_42740164/article/details/119375782?ops_request_misc=%257B%2522request%255Fi ...

  2. NAT与NAT实验

    1.NAT与NAT实验 NAT(网络地址翻译) 一个数据包目的ip或者源ip为私网地址, 运营商的设备无法转发数据. 实际场景问题 如下图 201.0.0.1 公网地址?   买的 运营商给你的​19 ...

  3. 【Unity3D】平面光罩特效

    1 前言 ​ 屏幕深度和法线纹理简介中对深度和法线纹理的来源.使用及推导过程进行了讲解,激光雷达特效中讲述了一种重构屏幕像素点世界坐标的方法,本文将沿用激光雷达特效中重构像素点世界坐标的方法,实现平面 ...

  4. Jni GetMethodID中函数标识sig的详细解释

    在 JNI(Java Native Interface)中,GetMethodID 函数用于获取 Java 类的方法的标识符.这个函数的详细解释如下: cCopy code jmethodID Get ...

  5. 三维模型OSGB格式轻量化的纹理压缩和质量保持分析

    三维模型OSGB格式轻量化的纹理压缩和质量保持分析 在三维模型应用中,纹理数据是一个重要的部分,可以为模型增加更多的真实感和细节.但是,由于纹理数据通常会占用大量的存储空间和传输带宽,因此,在OSGB ...

  6. 如何获取和分析Java堆信息

    引言 在Java应用程序的开发和维护过程中,了解和分析Java堆信息是一项重要的任务.本文将介绍如何获取Java堆信息的不同方法,并提供一些分析堆信息的实用技巧. 获取Java堆信息的方法 Java虚 ...

  7. Spring Boot虚拟线程与Webflux在JWT验证和MySQL查询上的性能比较

    早上看到一篇关于Spring Boot虚拟线程和Webflux性能对比的文章,觉得还不错.内容较长,我就不翻译了,抓重点给大家介绍一下这篇文章的核心内容,方便大家快速阅读. 测试场景 作者采用了一个尽 ...

  8. To_Heart—题解——好多好多!

    1.CF1860D link && submission 发现自己并不会处理纯纯的 dp 甚至自己根本不会dp! 定义 dp_{i,j,k} 状态表示前 i 个字符有 j 个 0, 0 ...

  9. spark修改控制台输出日志级别

    spark修改控制台输出日志级别 修改conf/log4j.properties cd $SPARK_HOME/conf cp log4j.properties.template ./log4j.pr ...

  10. oracle的根容器下新建pdb容器及本地用户

    在Oracle12C根容器下,新建pdb,要求根据种子pdb建目的pdb:db_test,配置监听:在目的pdb下建本地用户 首先根据种子pdb新建目的pdb 1.管理员身份登录 C:\WINDOWS ...