Hello guys, Java Database Connectivity, the JDBC API supports three types of parameters, I mean, IN, OUT, and INOUT. They are used to bind values into SQL statements. An IN parameter is the one whose value is unknown when the SQL statement is created and you bind values using various setXXX() method depending upon the type of column those IN parameter refers in SQL query. For example in SQL query, SELECT * from EMPLOYEE where EMP_ID=? if the EMP_ID is a VARCHAR column then you must call the setString() method to pass the value to the IN parameter.
On the other hand, the INOUT parameter is the one that provides both input and output values. You can not only bind variables with the setXXX() methods but also can retrieve values with the getXXX() methods.
A PreparedStatement object only uses the IN parameter. but the CallableStatement object can use all three types of parameters. These were some fundamental differences between IN, OUT, and INOUT parameters in JDBC. Let's see a couple of more differences in point format.
IN vs OUT vs INOUT parameters in Java JDBC Stored Procedure
Now, you know the definition and purpose of IN, OUT, and INOUT parameters. Let's compare them against each other1. Main difference between IN and OUT parameters is that IN is used to pass data to the database via SQL query, while OUT parameter is used to read results from the database, especially in the case of stored procedure.
2. Second difference is that the value of IN paraemter is provided using setXXX() mehtod like the setString(), setInt(), while value of OUT parameter is retrieved using getXXX() method like the getString(), getInt() etc.
3. IN Parameter is used by both PreparedStatement and CallableStatement but OUT parameter can only be used with CallableStatement.
4. INOUT parameters provide both input and output values. You bind variables with the setXXX() methods and retrieve values with the getXXX() methods.
That's all about the difference between IN, OUT, and INOUT parameters in JDBC. Remember, you can use IN parameter to pass input arguments to the stored procedure and can use OUT parameters to retreive results from a stored procedure. You can also use the INOUT parameters to both send inputs as well as retrieve results. The most important thing is that JDBC binds them using both setter and getter methods.
- Top 5 Free JDBC Courses for Java Programmers (free courses)
- Difference between the Callable and Prepared Statement? (answer)
- 10 JDBC Best Practices Every Java Programmer should follow (read)
- How to connect to MySQL database from Java Program? (tutorial)
- JDBC Batch Insert and Update example using PreparedStatement (tutorial)
- Difference between java.sql.Date, java.sql.Timestamp, and java.util.Date in JDBC? (answer)
- Difference between Type 1 and Type 4 JDBC drivers (answers)
- Top 10 JDBC Interview Question for Java programmers (read)
- 6 Essential JDBC Performance tips for Java Programmers (tips)
- How to connect to SQL Server database from Java (example)
No comments:
Post a Comment
Feel free to comment, ask questions if you have any doubt.