Conditional branching of the result of SQL statement to search only one in Java

I recently studied JDBC (Java Database Connectivity) a little. I searched only one case from the database, and I was troubled with the conditional branching method when getting the result, so I will leave it as a memo.

Connection con = null;
Statement stmt = null;
ResultSet res = null;
String sql = "SELECT * FROM DATABASE WHERE COLUMN = 〇〇";

try{
    con.DriveManager.getConnection(url, user, password);
    stmt.con.createStatement();
    res.stmt.executeQuery(sql);

    if(res.next()){
        //Processing when there is a result
    }else{
        //Processing when there is no result
}catch(SQLException e){
    //Processing when the SQL statement is incorrect
}finally{
    //Close processing etc.
}

Recommended Posts

Conditional branching of the result of SQL statement to search only one in Java
I want to simplify the conditional if-else statement in Java
Get the result of POST in Java
How to increment the value of Map in one line in Java
Sample code to get the values of major SQL types in Java + MySQL 8.0
[Java] [Microsoft] Things to be aware of when including the JDBC driver for SQL Server in one jar
How to derive the last day of the month in Java
Be sure to compare the result of Java compareTo with 0
Sample code to get the values of major SQL types in Java + Oracle Database 12c
[Java] It seems that `0 <hoge <10` cannot be written in the conditional expression of the ʻif` statement.
Java study # 4 (conditional branching / if statement)
Fix the file name of war to the one set in Maven
The milliseconds to set in /lib/calendars.properties of Java jre is UTC
How to get the length of an audio file in java
[Introduction to Java] Conditional branching (if statement, if-else statement, else if statement, ternary operator, switch statement)
Java reference to understand in the figure
The story of forgetting to close a file in Java and failing
[Java Servlet] The road of Senri is also one step to the first
How to find the total number of pages when paging in Java
How to get the date in java
Output of the book "Introduction to Java"
How to get the absolute path of a directory running in Java
[Java] Output the result of ffprobe -show_streams in JSON and map it to an object with Jackson
The story of writing Java in Emacs
Basics of Java development ~ How to write a program (flow and conditional branching) ~
Summarize the life cycle of Java objects to be aware of in Android development
Make the JSON of the snake case correspond to the field of the camel case in Java (JVM)
Let's refer to C ++ in the module of AndroidStudio other project (Java / kotlin)
[Java] Is it unnecessary to check "identity" in the implementation of the equals () method?
The story of low-level string comparison in Java
[Java] Handling of JavaBeans in the method chain
The story of making ordinary Othello in Java
About the idea of anonymous classes in Java
The story of learning Java in the first programming
Measure the size of a folder in Java
How to display the result of form input
[Java] How to get the authority of the folder
Import files of the same hierarchy in Java
Java Welcome to the Swamp of 2D Arrays
[Java] When putting a character string in the case of a switch statement, it is necessary to make it a constant expression
[Ruby] When you want to assign the result obtained by conditional branching to a variable and put it in the argument
How to get the class name of the argument of LoggerFactory.getLogger when using SLF4J in Java
The part I was addicted to in "Introduction to Ajax in Java Web Applications" of NetBeans
# 1_JAVA I want to get the index number by specifying one character in the character string.
[Java] How to display the day of the week acquired by LocalDate, DateTimeformatter in Japanese
Summary of how to use the proxy set in IE when connecting with Java
[Java] How to get the URL of the transition source
Get the URL of the HTTP redirect destination in Java
[Ruby] How to use standard output in conditional branching
[Java] How to omit the private constructor in Lombok
Omission of curly braces in if statement (Java silver)
How to write Scala from the perspective of Java
Return the execution result of Service class in ServiceResponse class
Understand the characteristics of Scala in 5 minutes (Introduction to Scala)
Source used to get the redirect source URL in Java
[Java] Get the file in the jar regardless of the environment
Java classes and instances to understand in the figure
Change the storage quality of JPEG images in Java
Summary of how to implement default arguments in Java
Java: Use Stream to sort the contents of the collection
Summarize the additional elements of the Optional class in Java 9