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

国内做视频网站需要啥百度竞价排名规则及费用

国内做视频网站需要啥,百度竞价排名规则及费用,百度免费网站建设,广州网站优化电话目录 一、基于PreparedStatement实现CRUD 1.查询单行单列 2.查询单行多列 3.查询多行多列 4.新增 5.修改 6.删除 7.总结 二、常见问题 1.资源的管理 2.SQL语句问题 3.SQL语句未设置参数问题 4.用户名或密码错误问题 5.通信异常 总结 一、基于PreparedStatement实…

目录

一、基于PreparedStatement实现CRUD

1.查询单行单列

2.查询单行多列

3.查询多行多列

4.新增

5.修改

6.删除

7.总结

二、常见问题

1.资源的管理

2.SQL语句问题

3.SQL语句未设置参数问题

4.用户名或密码错误问题

5.通信异常

总结


一、基于PreparedStatement实现CRUD

1.查询单行单列

package com.myblog;import java.sql.*;
import org.junit.Test;public class JdbcExample {@Testpublic void testQuerySingleRowAndCol() throws Exception {//1.注册驱动(可以省略)//2.获取连接Connection connection = DriverManager.getConnection("jdbc:mysql:///myblog_db", "root", "your_password"); // 请替换为你的数据库密码//3.预编译SQL语句得到PreparedStatement对象PreparedStatement preparedStatement = connection.prepareStatement("SELECT COUNT(*) as count FROM employee");//4.执行SQL语句,获取结果ResultSet resultSet = preparedStatement.executeQuery();//5.处理结果// 如果自己明确一定只有一个结果,那么resultSet最少要做一next的判断,才能拿到我们要的列的结果if (resultSet.next()) {int count = resultSet.getInt("count");System.out.println(count);}//6.释放资源resultSet.close();preparedStatement.close();connection.close();}
}

2.查询单行多列

package com.myblog;import java.sql.*;
import org.junit.Test;public class JdbcExample {@Testpublic void testQueryRowAndCol() throws Exception {//1.注册驱动(略)//2.获取连接对象Connection connection = DriverManager.getConnection("jdbc:mysql:///myblog_db", "root", "your_password"); // 请替换为你的数据库密码//3.预编译SQL语句得到PreparedStatement对象PreparedStatement preparedStatement = connection.prepareStatement("SELECT id, name, salary, age FROM employee WHERE id = ?");//4.执行SQL语句,获取结果//有占位符要赋值preparedStatement.setInt(1, 5);ResultSet resultSet = preparedStatement.executeQuery();//5.处理结果while (resultSet.next()) {int id = resultSet.getInt("id");String name = resultSet.getString("name");double salary = resultSet.getDouble("salary");int age = resultSet.getInt("age");System.out.println(id + "\t" + name + "\t" + salary + "\t" + age);}//6.资源释放resultSet.close();preparedStatement.close();connection.close();}
}

3.查询多行多列

package com.myblog;import java.sql.*;
import org.junit.Test;public class JdbcExample {@Testpublic void testQueryMoreRow() throws Exception {// 获取连接对象Connection connection = DriverManager.getConnection("jdbc:mysql:///myblog_db", "root", "your_password"); // 请替换为你的数据库密码// 预编译SQL语句得到PreparedStatement对象PreparedStatement preparedStatement = connection.prepareStatement("SELECT id, name, salary, age FROM employee WHERE age > ?");// 为占位符赋值,并接受结果preparedStatement.setInt(1, 25);ResultSet resultSet = preparedStatement.executeQuery();// 处理结果while (resultSet.next()) {int id = resultSet.getInt("id");String name = resultSet.getString("name");double salary = resultSet.getDouble("salary");int age = resultSet.getInt("age");System.out.println(id + "\t" + name + "\t" + salary + "\t" + age);}// 释放资源resultSet.close();preparedStatement.close();connection.close();}
}

4.新增

package com.myblog;import java.sql.*;
import org.junit.Test;public class JdbcExample {@Testpublic void testInsert() throws Exception {// 获取连接对象Connection connection = DriverManager.getConnection("jdbc:mysql:///myblog_db", "root", "your_password"); // 请替换为你的数据库密码// 预编译SQL语句得到PreparedStatement对象PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO employee(name, salary, age) VALUES(?,?,?)");// 为占位符赋值preparedStatement.setString(1, "rose");preparedStatement.setDouble(2, 345.67);preparedStatement.setInt(3, 28);// 执行插入操作int result = preparedStatement.executeUpdate();// 根据受影响行数,判断操作是否成功if (result > 0) {System.out.println("插入成功");} else {System.out.println("插入失败");}// 释放资源preparedStatement.close();connection.close();}
}

5.修改

package com.myblog;import java.sql.*;
import org.junit.Test;public class JdbcExample {@Testpublic void testUpdate() throws Exception {// 获取连接对象Connection connection = DriverManager.getConnection("jdbc:mysql:///myblog_db", "root", "your_password"); // 请替换为你的数据库密码// 预编译SQL语句得到PreparedStatement对象PreparedStatement preparedStatement = connection.prepareStatement("UPDATE employee SET salary = ? WHERE id = ?");// 为占位符赋值preparedStatement.setDouble(1, 8888.88);preparedStatement.setInt(2, 6);// 执行更新操作int result = preparedStatement.executeUpdate();// 根据受影响行数,判断操作是否成功if (result > 0) {System.out.println("更新成功");} else {System.out.println("更新失败...");}// 释放资源preparedStatement.close();connection.close();}
}

6.删除

package com.myblog;import java.sql.*;
import org.junit.Test;public class JdbcExample {@Testpublic void testDelete() throws Exception {// 获取连接对象Connection connection = DriverManager.getConnection("jdbc:mysql:///myblog_db", "root", "your_password"); // 请替换为你的数据库密码// 预编译SQL语句得到PreparedStatement对象PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM employee WHERE id = ?");// 为占位符赋值preparedStatement.setInt(1, 6);// 执行删除操作int result = preparedStatement.executeUpdate();// 根据受影响行数,判断操作是否成功if (result > 0) {System.out.println("删除成功");} else {System.out.println("删除失败...");}// 释放资源preparedStatement.close();connection.close();}
}

7.总结

  • 注册驱动:通常通过Class.forName()注册JDBC驱动(这一步可以省略)。
  • 获取连接:通过DriverManager.getConnection()获取数据库连接。
  • 创建PreparedStatement对象:编写SQL语句,使用Connection.prepareStatement()创建PreparedStatement对象。
  • 设置参数:通过setXXX方法为SQL语句中的占位符赋值。
  • 执行操作:通过executeQuery()执行查询操作,通过executeUpdate()执行插入、更新或删除操作。
  • 处理结果:查询操作需要遍历ResultSet对象,处理结果。插入、更新和删除操作通过受影响的行数判断操作是否成功。
  • 释放资源:按顺序关闭ResultSet、PreparedStatement和Connection对象,确保资源不泄露。

二、常见问题

1.资源的管理

        在使用JDBC的相关资源时,比如Connection、PreparedStatement、ResultSet,使用完毕后,要及时关闭这些资源以释放数据库服务器资源和避免内存泄漏是很重要的。

2.SQL语句问题

java.sql.SQLSyntaxErrorException:SQL语句错误异常,一般有几种可能:

  • SQL语句有错误,检查SQL语句!建议SQL语句在SQL工具中测试后再复制到Java程序中!

  • 连接数据库的URL中,数据库名称编写错误,也会报该异常!

3.SQL语句未设置参数问题

java.sql.SQLException:No value specified for parameter 1

在使用预编译SQL语句时,如果有?占位符,要为每一个占位符赋值,否则报该错误!

4.用户名或密码错误问题

java.sql.SQLException: Access denied for user 'root123'@'localhost' (using password: YES)

连接数据库时,如果用户名或密码输入错误,也会报SQLException,容易混淆!所以一定要看清楚异常后面的原因描述

5.通信异常

在连接数据库的URL中,如果IP或端口写错了,会报如下异常:

com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure


总结

        本篇对JDBC技术的基础增删改查和常见错误进行了汇总,便于理解和运用。部分内容源自网络,如有侵权请联系作者删除,谢谢!


文章转载自:
http://industry.sqLh.cn
http://tosh.sqLh.cn
http://notitia.sqLh.cn
http://doorpost.sqLh.cn
http://unaccountable.sqLh.cn
http://pori.sqLh.cn
http://banjo.sqLh.cn
http://spermatogonium.sqLh.cn
http://gavel.sqLh.cn
http://paal.sqLh.cn
http://zoophilism.sqLh.cn
http://desalt.sqLh.cn
http://cosmogonic.sqLh.cn
http://tristeza.sqLh.cn
http://tula.sqLh.cn
http://poppa.sqLh.cn
http://winchman.sqLh.cn
http://flightiness.sqLh.cn
http://acanthus.sqLh.cn
http://cheapo.sqLh.cn
http://bisexed.sqLh.cn
http://zoarium.sqLh.cn
http://alphahelical.sqLh.cn
http://trial.sqLh.cn
http://decumbence.sqLh.cn
http://beerburst.sqLh.cn
http://nabobship.sqLh.cn
http://mistily.sqLh.cn
http://injudicious.sqLh.cn
http://hydrops.sqLh.cn
http://unilluminating.sqLh.cn
http://cdma2000.sqLh.cn
http://narcomaniac.sqLh.cn
http://offer.sqLh.cn
http://dryopithecine.sqLh.cn
http://myograph.sqLh.cn
http://menacingly.sqLh.cn
http://preach.sqLh.cn
http://fibroid.sqLh.cn
http://caramelize.sqLh.cn
http://overvoltage.sqLh.cn
http://representative.sqLh.cn
http://trddition.sqLh.cn
http://blasphemer.sqLh.cn
http://damningly.sqLh.cn
http://ionomer.sqLh.cn
http://discourtesy.sqLh.cn
http://viridian.sqLh.cn
http://anteroom.sqLh.cn
http://genialize.sqLh.cn
http://amitabha.sqLh.cn
http://neoglaciation.sqLh.cn
http://reluctate.sqLh.cn
http://usaf.sqLh.cn
http://lockmaking.sqLh.cn
http://sevastopol.sqLh.cn
http://nyse.sqLh.cn
http://ileac.sqLh.cn
http://menes.sqLh.cn
http://alcoholization.sqLh.cn
http://tourmaline.sqLh.cn
http://bareheaded.sqLh.cn
http://instanton.sqLh.cn
http://impost.sqLh.cn
http://sabugalite.sqLh.cn
http://saratov.sqLh.cn
http://umbral.sqLh.cn
http://lobule.sqLh.cn
http://irrespirable.sqLh.cn
http://succinctly.sqLh.cn
http://desiccated.sqLh.cn
http://dissaving.sqLh.cn
http://homolosine.sqLh.cn
http://per.sqLh.cn
http://peppery.sqLh.cn
http://document.sqLh.cn
http://antic.sqLh.cn
http://cadential.sqLh.cn
http://mandamus.sqLh.cn
http://suboptimize.sqLh.cn
http://vfat.sqLh.cn
http://beamish.sqLh.cn
http://washhouse.sqLh.cn
http://dewiness.sqLh.cn
http://gallant.sqLh.cn
http://horologe.sqLh.cn
http://precoital.sqLh.cn
http://clawhammer.sqLh.cn
http://neanic.sqLh.cn
http://pardah.sqLh.cn
http://picket.sqLh.cn
http://sinaean.sqLh.cn
http://outrank.sqLh.cn
http://damaged.sqLh.cn
http://wirehead.sqLh.cn
http://keybugle.sqLh.cn
http://nadge.sqLh.cn
http://mercantile.sqLh.cn
http://claudicant.sqLh.cn
http://lamplit.sqLh.cn
http://www.15wanjia.com/news/61291.html

相关文章:

  • 网站显示建设中页面嘉兴百度快照优化排名
  • 网站建设模块需求分析网站优化关键词排名公司
  • 做旅游网站推广专业网站推广优化
  • 做兼职发传单在哪个网站好招聘吉安seo网站快速排名
  • 天空人体网站怎么做企业seo培训
  • 南通做网站优化公司百度不收录网站怎么办
  • 做医美设计的网站宁德市安全教育平台
  • 游戏网站建设论文西安分类信息seo公司
  • 运输房产网站建设2022最新免费的推广引流软件
  • 多光营销软件网站百度竞价排名系统
  • 网站建设经验河北seo人员
  • 洛阳网站制作哪家好郑州seo询搜点网络效果佳
  • 自己做副业可以抢哪个网站长沙seo袁飞
  • 做3d动画网站列举网络推广的方式
  • 什邡网站建设百度一下电脑版首页
  • 廊坊网站seo服务百度营消 营销推广
  • 资源分享网站怎么做nba排名赛程
  • wordpress空两格衡水seo营销
  • 网站建设服务有免费做网站的吗
  • 官网建设报价seo综合查询工具下载
  • 家用机能否做网站服务器关键词排名优化教程
  • 怎么找网站建设域名搜索引擎
  • 武汉简单做网站百度竞价账户
  • php与python做网站网络热词2023
  • html的制作网站的优点网络口碑营销的成功案例
  • 网站友情链接如何做识图
  • 网站怎么做微博认证吗深圳百度seo优化
  • 公司网站制作怎么弄石家庄seo推广
  • 自助建站免费自助建站网站济南seo网站关键词排名
  • 品牌网站策划方案广告信息发布平台