java-web JDBC

jdbc

java 复制代码
package com.gyk.jdbc;


import com.mysql.jdbc.Driver;
import org.junit.jupiter.api.Test;

import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * ClassName: D
 * Package: com.gyk.jdbc
 * Description:
 *
 * @Author Samuel
 * @Create 2024/8/1 13:05
 * @Version 1.0
 */
public class D {
    @Test
    public void m1() throws ClassNotFoundException, SQLException {
        //连接本地 mysql
        //获取驱动类
//        Class.forName("com.mysql.jdbc.Driver");
        //url
        String url = "jdbc:mysql://localhost:3306/test?useSSL=false";
        //username password
        String username = "root";
        String password = "root";
        Connection connection = DriverManager.getConnection(url, username, password);
        System.out.println(connection);
//        DriverManager

    }
}
复制代码
/**
 * 在 JDBC 中,PreparedStatement.execute() 方法返回一个布尔值,
 * 表示执行的 SQL 语句是否返回了一个 ResultSet 对象。
 * 对于 INSERT、UPDATE 和 DELETE 语句,execute() 方法通常返回 false,
 * 因为这些语句不会返回 ResultSet 对象。
 */
复制代码
executeUpdate

Executes the SQL statement in this PreparedStatement object, which must be an SQL Data Manipulation Language (DML) statement, such as INSERT, UPDATE or DELETE; or an SQL statement that returns nothing, such as a DDL statement.

Returns:

either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing

Throws:

SQLException -- if a database access error occurs; this method is called on a closed PreparedStatement or the SQL statement returns a ResultSet object

SQLTimeoutException -- when the driver has determined that the timeout value that was specified by the setQueryTimeout method has been exceeded and has at least attempted to cancel the currently running Statement

java 复制代码
 Boolean aBoolean = preparedStatement.execute();

Returns:
true if the first result is a ResultSet object; 
false if the first result is an update count or there is no result


select * 得到 true ( 15 rows in set (0.00 sec))

insert update delete 得到false(Query OK, 1 row affected (0.00 sec))
相关推荐
Han.miracle26 分钟前
数据结构——二叉树的从前序与中序遍历序列构造二叉树
java·数据结构·学习·算法·leetcode
Le1Yu1 小时前
分布式事务以及Seata(XA、AT模式)
java
2501_915918411 小时前
掌握 iOS 26 App 运行状况,多工具协作下的监控策略
android·ios·小程序·https·uni-app·iphone·webview
寒山李白2 小时前
关于Java项目构建/配置工具方式(Gradle-Groovy、Gradle-Kotlin、Maven)的区别于选择
java·kotlin·gradle·maven
无妄无望3 小时前
docker学习(4)容器的生命周期与资源控制
java·学习·docker
MC丶科3 小时前
【SpringBoot 快速上手实战系列】5 分钟用 Spring Boot 搭建一个用户管理系统(含前后端分离)!新手也能一次跑通!
java·vue.js·spring boot·后端
千码君20163 小时前
React Native:从react的解构看编程众多语言中的解构
java·javascript·python·react native·react.js·解包·解构
2501_915909064 小时前
iOS 混淆实战,多工具组合完成 IPA 混淆与加固(源码 + 成品 + 运维一体化方案)
android·运维·ios·小程序·uni-app·iphone·webview
夜白宋4 小时前
【word多文档docx合并】
java·word