package com.lin; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; /** * jdbc 工具类 */ public class jdbcUtil { private static String driver = "com.mysql.jdbc.Driver"; private static String jdbcUrl = "com.mysql.jdbc.Driver"; private static String userName = "root"; private static String password = "chaoge"; //静态代码块,程序加载时执行,且执行一次 static { try { Class.forName("driver"); } catch (ClassNotFoundException e) { e.printStackTrace(); } } //获取Connection 对象 public static Connection getConnection() { Connection connection = null; try { connection = DriverManager.getConnection(jdbcUrl, userName, password); } catch (SQLException e) { e.printStackTrace(); } return connection; } //关闭Statement public static void closeStatement(Statement statement) { if (statement != null) { try { statement.close(); } catch (SQLException e) { e.printStackTrace(); } } } //关闭Connection public static void closeConnection(Connection connection) { if (connection != null) { try { connection.close(); } catch (SQLException e) { e.printStackTrace(); } } } //关闭所有资源 public static void closeResource(Statement statement, Connection connection) { closeStatement(statement); closeConnection(connection); } }
有了上面的工具类,那我们就可以精简我们的代码了
package com.lin; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; /** * 使用工具类 */ public class jdbcTest1 { //向Departments 表中添加一个数据 public void insertDepartments(String department_name,int location_id) { Connection connection = null; Statement statement = null; try { //1.注册驱动 获取connection 对象 connection = jdbcUtil.getConnection(); //编辑sql语句 String sql = "insert into departments values(default,'" + department_name + "','" + location_id + "')"; //创建Statement对象用于发送数据 statement = connection.createStatement(); int flag = statement.executeUpdate(sql); System.out.println(flag); } catch (Exception e) { e.printStackTrace(); } finally { jdbcUtil.closeStatement(statement); jdbcUtil.closeConnection(connection); } } //更新departments 表中的department_di 为6 的数据 部门名称修改为java研发部 location_id改为6 public void updateDepartments( String department_id,String department_name, int location_id){ Connection connection = null; Statement statement = null; try { connection= jdbcUtil.getConnection(); //创建Statement对象用于发送数据 statement =connection.createStatement(); //创建SQL语句 String sql = "update departments d set d.department_name = '"+department_name+"',d.location_id = "+location_id+" where d.department_id ="+department_id; int falg = statement.executeUpdate(sql); if (falg ==1){ System.out.println("修改成功"); }else { System.out.println("修改失败"); } } catch (Exception e) { e.printStackTrace(); } finally { jdbcUtil.closeResource(statement,connection); } } public static void main(String[] args) { com.lin.jdbcTest jdbcTest = new com.lin.jdbcTest(); // jdbcTest.insertDepartments("事业部",11); jdbcTest.updateDepartments("7","推广销售部",7); } }
如果您发现该资源为电子书等存在侵权的资源或对该资源描述不正确等,可点击“私信”按钮向作者进行反馈;如作者无回复可进行平台仲裁,我们会在第一时间进行处理!
了解了上面两种网络模型和协议,那么网络模型和协议究竟是干什么呢?网路模型的通讯过程是怎样的呢?
在使用Gin开发web应用的时候,业务异常是很常见的,通常我们会为每个异常情况定义一个唯一的error。同时当发生异常的时候,我们也需要把异常信息放入到接口的响应信息里面,方便页面上做提示。
一、锁的原理 为了实现互斥锁操作,大多数体系结构都提供了swap或exchange指令,该指令的作用是把寄存器和内存单元的数据相交换,由于只有一条指令,保证了原子性,即使是多处理器平台,访问内存的 总线周期也有先后,一个处理器上的交换指令执行时另一个处理器的交换指令只能等待总线周期。
摘要 近日浏览网上一些图片提取文字的网站,觉得甚是有趣,花费半日也做了个在线图片识别程序,完成了两个技术方案的选择,一是tesseract+python flask的方案实现,二是tesseract+spring web的技术解决方案,并简作论述,与君共勉。
Java爬虫实战:快速抓取网页数据的方法与技巧 引言:随着互联网的发展,海量的信息被存储在网页中,人们想要从中获取有用的数据变得越来越困难。而使用爬虫技术,我们可以快速、自动地抓取网页数据,提取出我们需要的有用信息。本文将介绍使用Java进行爬虫开发的方法与技巧,并提供具体的代码示例。 一、选择合适的爬虫框架在Java领域,有许多优秀的爬虫框架可供选择,如Jsoup、Crawler4j等。选择合适的爬虫框架可以极大地简化开发过程,提高爬虫效率。
直接从DWG文件中提取建筑模型进行节能设计。可以最大程度的减轻建筑师的工作量,在方案、扩初和施工图等不同设计阶段方便的进行节能设计,避免了二次建模的工作。
机器学习在当今技术发展中扮演着越来越重要的角色。随着数据规模的不断增长,处理和分析大数据变得尤为关键。在机器学习中,数据降维和特征提取是两个非常重要的任务,它们可以帮助我们减少数据集的维度,提取关键信息,从而更好地进行模型训练和预测。本文将介绍如何使用PHP进行数据降维与特征提取,并给出相应的代码示例。
一.说明 我们在使用SpringBoot的时候常常要引入一些Starter,例如spring-boot-starter-web,官方为我们提供了几乎所有的默认配置,很好的降低了使用框架时的复杂度。 所以在用xxx-starter的时候,可以不用费心去写一些繁琐的配置文件,即使必要的配置在application.properties或application.yml中配置就可以了,当你实现了一个Starter,可以在不同的项目中复用,非常方便,今天我们来编写自己的Starter
关于Java封装遇到的问题
封装 定义:隐藏对象的属性和实现细节,仅对外公开接口,控制在程序中属性的读和修改的访问级别。 目的:增强安全性和简化编程,使用者不必了解具体的实现细节,而只是要通过外部接口,一特定的访问权限来使用类的成员。 作用:降低耦合。 基本要求:私有成员是在封装体内被隐藏的部分,只有类的成员函数才可以访问私有成员,而在类体外的函数时不能访问的;公有成员是封装体与外界的一个接口,类体外的函数可以访问公有成员;保护成员是只有该类的成员函数和该类的派生类才可以访问的。 封装性实际上是由编译器去识别关键字public、private和protected,体现在类的成员可以有公有成员(public),私有成员(private),保护成员(protected)。
prtyaa 收益393.62元
zlj141319 收益218元
1843880570 收益214.2元
IT-feng 收益209.03元
风晓 收益208.24元
777 收益172.71元
Fhawking 收益106.6元
信创来了 收益105.84元
克里斯蒂亚诺诺 收益91.08元
技术-小陈 收益79.5元
扫一扫关注公众号
扫一扫加入交流群
加入交流群
请使用微信扫一扫!