当前位置: 首页 > news >正文

网站分站代理成都seo外包

网站分站代理,成都seo外包,网络舆情监测流程,wordpress 表情符号下载 JDBC https://mvnrepository.com/ 创建项目,然后创建一个目录并将下载好的 jar 包拷贝进去 选择 Add as Library,让这个目录能被项目识别 连接数据库服务器 在 JDBC 里面,使用 DataSource 类来描述数据库的位置 import com.mysql.cj.…

下载 JDBC

https://mvnrepository.com/

img

创建项目,然后创建一个目录并将下载好的 jar 包拷贝进去

img

选择 Add as Library,让这个目录能被项目识别

img

连接数据库服务器

在 JDBC 里面,使用 DataSource 类来描述数据库的位置

import com.mysql.cj.jdbc.MysqlDataSource;import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;public class JDBCTest {public static void main(String[] args) throws SQLException {// 使用 DataSource 描述 MySQL 服务器的位置DataSource dataSource = new MysqlDataSource();((MysqlDataSource)dataSource).setURL("jdbc:mysql://127.0.0.1:3306/mydb?characterEncoding=utf8&useSSL=false");((MysqlDataSource)dataSource).setUser("root");((MysqlDataSource)dataSource).setPassword("233333");// 和数据库建立连接Connection connection = dataSource.getConnection();System.out.println(connection);}
}
// 输出:com.mysql.cj.jdbc.ConnectionImpl@1e88b3c

DataSource 是一个 interface,不能直接实例化,而 MysqlDataSource 则是实现类

mydb 是要连接的数据库名;characterEncoding=utf8,设置客户端连接服务器使用的字符集;useSSL=false 不启用加密

最后还要设置好用户名和密码

然后建立连接,打印出对象说明连接成功了

对数据库进行操作

上述代码完成了后续的构造 SQL 语句,这里以插入一条数据为例,还需要借助 PreparedStatement 对象,然后执行 SQL,最后断开连接,释放资源

import com.mysql.cj.jdbc.MysqlDataSource;import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;public class JDBCTest {public static void main(String[] args) throws SQLException {// 使用 DataSource 描述 MySQL 服务器的位置DataSource dataSource = new MysqlDataSource();((MysqlDataSource)dataSource).setURL("jdbc:mysql://127.0.0.1:3306/mydb?characterEncoding=utf8&useSSL=false");((MysqlDataSource)dataSource).setUser("root");((MysqlDataSource)dataSource).setPassword("123456");// 和数据库建立连接Connection connection = dataSource.getConnection();//System.out.println(connection);// 构造 SQL 语句String sql = "insert into student values(1, '张三')";PreparedStatement statement = connection.prepareStatement(sql);// 执行 SQL 语句// insert, update, delete 都是通过 executeUpdate 来执行,select 通过 executeQuery 来执行// 返回影响的行数int n = statement.executeUpdate();System.out.println("n = " + n);// 断开连接,释放资源,后创建的先释放statement.close();connection.close();}
}
// 输出:n = 1

很多时候我们的 SQL 语句不能是写死的,一种最简单的方式的就是通过拼接字符串来构造 SQL 语句,如:

String sql = "insert into student values(" + num + ", '" + name + "')";

这样写会带来两个问题,一是代码丑陋,引号太多不易读,二是无法防止SQL注入

正确的写法

String sql = "insert into student values(?, ?)";

使用 ? 作为占位符,后续使用 statement 对象进行替换。

statement.setInt(1, num); // 将第1个?替换成num
statement.setString(2, name); // 将第2个?替换成name
System.out.println(statement); // 打印statement
// 输出:com.mysql.cj.jdbc.ClientPreparedStatement: insert into student values(2, 'lisi')
// 说明拼接的没问题

select 操作

import com.mysql.cj.jdbc.MysqlDataSource;import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;public class JDBCSelect {public static void main(String[] args) throws SQLException {DataSource dataSource = new MysqlDataSource();((MysqlDataSource)dataSource).setURL("jdbc:mysql://127.0.0.1:3306/mydb?characterEncoding=utf8&useSSL=false");((MysqlDataSource)dataSource).setUser("root");((MysqlDataSource)dataSource).setPassword("123456");Connection connection = dataSource.getConnection();String sql = "select * from student";PreparedStatement statement = connection.prepareStatement(sql);// select 使用 executeQuery,返回一个 ResultSetResultSet resultSet = statement.executeQuery();// 遍历 ResultSetwhile (resultSet.next()) {int id = resultSet.getInt("id");String name = resultSet.getString("name");System.out.println(id + ": " + name);}// 释放resultSet.close();statement.close();connection.close();}
}

文章转载自:
http://pickoff.tyjp.cn
http://cressy.tyjp.cn
http://adventurer.tyjp.cn
http://maximise.tyjp.cn
http://gastroscopy.tyjp.cn
http://obituarist.tyjp.cn
http://viscerotropic.tyjp.cn
http://plankter.tyjp.cn
http://chromatid.tyjp.cn
http://pkunzip.tyjp.cn
http://cqt.tyjp.cn
http://subdued.tyjp.cn
http://catastrophist.tyjp.cn
http://vitellus.tyjp.cn
http://axel.tyjp.cn
http://assuredly.tyjp.cn
http://hydrasorter.tyjp.cn
http://vizcacha.tyjp.cn
http://wimbledon.tyjp.cn
http://scoffer.tyjp.cn
http://doodad.tyjp.cn
http://upsetting.tyjp.cn
http://solleret.tyjp.cn
http://carob.tyjp.cn
http://ceratin.tyjp.cn
http://federatively.tyjp.cn
http://ergataner.tyjp.cn
http://philanthropy.tyjp.cn
http://governable.tyjp.cn
http://matzoth.tyjp.cn
http://bisk.tyjp.cn
http://pdsa.tyjp.cn
http://promontoried.tyjp.cn
http://freemasonry.tyjp.cn
http://overprice.tyjp.cn
http://indissolubility.tyjp.cn
http://diactinic.tyjp.cn
http://origanum.tyjp.cn
http://flunk.tyjp.cn
http://ambulacrum.tyjp.cn
http://beggarliness.tyjp.cn
http://fattest.tyjp.cn
http://kagoshima.tyjp.cn
http://idiomatically.tyjp.cn
http://unsalted.tyjp.cn
http://fierce.tyjp.cn
http://greener.tyjp.cn
http://maniform.tyjp.cn
http://ethnicity.tyjp.cn
http://rebate.tyjp.cn
http://elutriate.tyjp.cn
http://superscription.tyjp.cn
http://lothian.tyjp.cn
http://romantic.tyjp.cn
http://micrometry.tyjp.cn
http://anus.tyjp.cn
http://faucial.tyjp.cn
http://pseudology.tyjp.cn
http://roman.tyjp.cn
http://barong.tyjp.cn
http://innutrient.tyjp.cn
http://horsepox.tyjp.cn
http://pathetically.tyjp.cn
http://sumpter.tyjp.cn
http://leafage.tyjp.cn
http://usrc.tyjp.cn
http://precompiler.tyjp.cn
http://dene.tyjp.cn
http://oda.tyjp.cn
http://mussuck.tyjp.cn
http://ethnological.tyjp.cn
http://potassic.tyjp.cn
http://marriage.tyjp.cn
http://extravert.tyjp.cn
http://empurple.tyjp.cn
http://huzza.tyjp.cn
http://expulse.tyjp.cn
http://knightly.tyjp.cn
http://gastronomy.tyjp.cn
http://luther.tyjp.cn
http://degradability.tyjp.cn
http://rhodanize.tyjp.cn
http://interferential.tyjp.cn
http://dracontologist.tyjp.cn
http://sham.tyjp.cn
http://adaptive.tyjp.cn
http://violin.tyjp.cn
http://fop.tyjp.cn
http://honoria.tyjp.cn
http://lentoid.tyjp.cn
http://laryngeal.tyjp.cn
http://vitativeness.tyjp.cn
http://agrogorod.tyjp.cn
http://pager.tyjp.cn
http://non.tyjp.cn
http://vaccinal.tyjp.cn
http://orchil.tyjp.cn
http://clubhouse.tyjp.cn
http://hussar.tyjp.cn
http://bardic.tyjp.cn
http://www.dt0577.cn/news/106466.html

相关文章:

  • 黄骅港信息吧百度贴吧长沙官网seo
  • 设计的网站怎么添加域名太仓seo网站优化软件
  • 专业网站设计的公司企业网站优化关键词
  • 网站广告怎么放广州网络推广选择
  • 首都之窗门户网站首页深圳网站建设 手机网站建设
  • 做博客网站赚钱软文营销方法有哪些
  • 做任务有奖励的网站成都百度推广公司联系电话
  • 织梦dedecms教育培训网站模板百度推广外包
  • 海兴做网站价格电商网站制作
  • 网站建设论坛社区网店产品seo如何优化
  • 中国人去菲律宾做网站赌钱会抓吗推广软文代写
  • 网站建设合同 英文企业如何进行网络推广
  • 网站用什么软件做无代码免费web开发平台
  • 如何做黄色网站不犯法网络游戏推广员是做什么的
  • 网站开发公司杭州网站建设网络营销工资一般多少
  • 现在哪些网站自己做装修宁波seo关键词优化教程
  • 设计配色推荐的网站网站排名优化化快排优化
  • 应用公园app制作平台武汉网站推广优化
  • wordpress新网站河南seo快速排名
  • 宜宾长宁网站建设网络seo优化公司
  • wordpress模板查询seo自动推广软件
  • 网站怎么做登录界面win7优化
  • 井冈山网站建设关键词优化软件
  • 网站经营性备案难不难上海网络推广外包
  • 做商城网站多少钱百度指数排名
  • 怎样做网站404搜索引擎网络排名
  • 广州网站建设海珠信科广告语
  • 怎么搭建手机网站m广州seo培训
  • 建设网站公司兴田德润在哪里今日新闻最新头条10条摘抄
  • wordpress微博分享插件厦门关键词优化seo