当前位置:网站首页>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
边栏推荐
- VIM usage
- Visual common drawing (V) scatter diagram
- UEditor之——图片上传组件大小4M的限制
- MBA-day5數學-應用題-工程問題
- MySQL how to merge the same data in the same table
- Arbitrary file reading vulnerability exploitation Guide
- SSH利用私钥无密钥连接服务器踩坑实录
- Full stack cross compilation x86 completion process experience sharing
- 【leetcode】199.二叉树的右视图
- Idea - indexing or scanning files to index every time you start
猜你喜欢
Net start MySQL MySQL service is starting MySQL service failed to start. The service did not report any errors.
Solution architect's small bag - 5 types of architecture diagrams
SQL Server recursive query of superior and subordinate
26. 删除有序数组中的重复项
A diary of dishes | 238 Product of arrays other than itself
Introduction to data analysis 𞓜 kaggle Titanic mission (III) - > explore data analysis
Visualized common drawing (II) line chart
Solutions to common problems in visualization (VIII) solutions to problems in shared drawing area
C语言之结构体(进阶篇)
Let the LAN group use the remote device
随机推荐
Read integrity monitoring techniques for vision navigation systems - 4 multiple faults in vision system
Visual Road (XII) detailed explanation of collection class
Google Earth Engine(GEE)——将原始影像进行升尺度计算(以海南市为例)
Example of pop-up task progress bar function based on pyqt5
MySql常用语句
Learning note 5 - gradient explosion and gradient disappearance (k-fold cross verification)
高价买来的课程,公开了!phper资料分享
Swagger2 接口如何导入Postman
Charles 功能介绍和使用教程
Image processing - Noise notes
UDP basic learning
mysql同一个表中相同数据怎么合并
UEditor之——图片上传组件大小4M的限制
Idea - indexing or scanning files to index every time you start
Visual common drawing (I) stacking diagram
SSH uses private key to connect to server without key
Typora operation skill description (I) md
全栈交叉编译X86完成过程经验分享
Restful、SOAP、RPC、SOA、微服务之间的区别
SQL Server recursive query of superior and subordinate