当前位置:网站首页>How to use JDBC callablestatement The wasnull () method is called to check whether the value of the last out parameter is SQL null
How to use JDBC callablestatement The wasnull () method is called to check whether the value of the last out parameter is SQL null
2022-04-23 10:56:00 【allway2】
This example shows you how to use CallableStatement.wasNull() Method is called to view the last OUT Whether the value of the parameter is SQL NULL.
package org.kodejava.jdbc; import java.math.BigDecimal; import java.sql.Connection; import java.sql.CallableStatement; import java.sql.DriverManager; import java.sql.Types; import java.sql.SQLException; public class WasNullExample { private static final String URL = "jdbc:mysql://localhost/kodejava"; private static final String USERNAME = "root"; private static final String PASSWORD = ""; public static void main(String[] args) { try (Connection connection = DriverManager.getConnection(URL, USERNAME, PASSWORD)) { // Prepares a call to the sored procedure String query = "call Get_Product_By_Price2(?, ?)"; CallableStatement cb = connection.prepareCall(query); // Sets the input parameter cb.setBigDecimal(1, new BigDecimal("50")); // Registers the OUT parameter cb.registerOutParameter(2, Types.VARCHAR); // Executes the query cb.executeQuery(); // Gets the OUT parameter value cb.getString(2); // Checks if the last OUT parameter has value of SQL NULL. // This method should be called only after calling a // getter method; otherwise, there is no value to use in // determining whether it is null or not. if (cb.wasNull()) { System.out.println("Product has an SQL NULL value"); } else { System.out.println("Product: " + cb.getString(2)); } } catch (SQLException e) { e.printStackTrace(); } } }
This is the stored procedure script we called in the above example. .
DELIMITER ;; DROP PROCEDURE IF EXISTS Get_Product_By_Price2;; CREATE PROCEDURE Get_Product_By_Price2( IN product_price DECIMAL(10, 2), OUT product_name VARCHAR(50)) BEGIN SELECT NAME INTO product_name FROM products WHERE price = product_price; END;; DELIMITER ;
Maven Dependencies
<!-- https://search.maven.org/remotecontent?filepath=mysql/mysql-connector-java/8.0.28/mysql-connector-java-8.0.28.jar --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.28</version> </dependency>
版权声明
本文为[allway2]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231051098115.html
边栏推荐
- 精彩回顾 | DEEPNOVA x Iceberg Meetup Online《基于Iceberg打造实时数据湖》
- Promise详解
- Typora operation skill description (I) md
- 19. Delete the penultimate node of the linked list (linked list)
- Understand the key points of complement
- C语言之结构体(进阶篇)
- How to quickly download vscode
- MBA-day5数学-应用题-工程问题
- CentOS/Linux安装MySQL
- 主流手机分辨率与尺寸
猜你喜欢

SSH利用私钥无密钥连接服务器踩坑实录
![[provincial election joint examination 2022 d2t1] card (state compression DP, FWT convolution)](/img/e4/3c47edbc3241ba86f10a1ac8a963fd.png)
[provincial election joint examination 2022 d2t1] card (state compression DP, FWT convolution)

得到知识服务app原型设计比较与实践

《Neo4j权威指南》简介,求伯君、周鸿袆、胡晓峰、周涛等大咖隆重推荐

Intuitive understanding entropy

How to quickly download vscode

Introduction to data analysis 𞓜 kaggle Titanic mission (IV) - > data cleaning and feature processing

景联文科技—专业数据标注公司和智能数据标注平台

Swagger2 接口如何导入Postman

Visual common drawing (IV) histogram
随机推荐
Cve-2019-0708 vulnerability exploitation of secondary vocational network security 2022 national competition
Ueditor -- limitation of 4m size of image upload component
软件测试人员,如何优秀的提Bug?
学习网站资料
我的创作纪念日
全栈交叉编译X86完成过程经验分享
Arbitrary file reading vulnerability exploitation Guide
Google Earth Engine(GEE)——将原始影像进行升尺度计算(以海南市为例)
使用 PHP PDO ODBC 示例的 Microsoft Access 数据库
Is the pointer symbol of C language close to variable type or variable name?
Deploy jar package
【leetcode】199. Right view of binary tree
Qinglong panel pull library command update [April 20, 2022] collection is not lost
Read integrity monitoring techniques for vision navigation systems
Using El popconfirm and El backtop does not take effect
SQLServer 查询数据库死锁
得到知识服务app原型设计比较与实践
19. Delete the penultimate node of the linked list (linked list)
Data analysis learning (I) data analysis and numpy Foundation
142. Circular linked list||