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))
相关推荐
Daniel 大东3 分钟前
BugJson因为json格式问题OOM怎么办
java·安全
Mr_Xuhhh7 分钟前
重生之我在学环境变量
linux·运维·服务器·前端·chrome·算法
永乐春秋1 小时前
WEB攻防-通用漏洞&文件上传&js验证&mime&user.ini&语言特性
前端
鸽鸽程序猿1 小时前
【前端】CSS
前端·css
Eastsea.Chen1 小时前
MTK Android12 user版本MtkLogger
android·framework
ggdpzhk1 小时前
VUE:基于MVVN的前端js框架
前端·javascript·vue.js
学不会•3 小时前
css数据不固定情况下,循环加不同背景颜色
前端·javascript·html
Theodore_10224 小时前
4 设计模式原则之接口隔离原则
java·开发语言·设计模式·java-ee·接口隔离原则·javaee
冰帝海岸5 小时前
01-spring security认证笔记
java·笔记·spring
活宝小娜6 小时前
vue不刷新浏览器更新页面的方法
前端·javascript·vue.js