In this JDBC section we are going to learn about the big decimal and how can be set it in the database table by using the PreparedStatement interface of java.sql package. But here arises a question, what is big decimal and which type to use this in the database. We know that using of both data types MySQL and Java programming language are not same. So mapping between both is essential to integrate to each other, here we will work on the big decimal data type in java to integrate in MySQL through the help of NUMERIC and DECIMAL data types. See detail description below:
Description of program:
In this program we are going to insert big decimal data type in the database table (bigdecimal) through the use of PreparedStatement interface. Here, first of all we need to establish the connection with MySQL database by using the JDBC driver. After establishing the connection we will give own query in the prepareStatement method that provides us the PreparedStatement object. Now we will add all data in the data according to database table (Records, sal) . The sal column contains the big decimal data types. When we will get added data in the database table then it will provide a message "Successfully!" otherwise it shows "SQL statement is not executed!".
Description of code:
This is the constructor of java.sql.BigDecimal class that takes one string type argument and translates it into a BigDecimal.
setBigDecimal( int index, BigDecimal big);
Above method takes integer type index number another is BigDecimal types number and sets an arguments to the given java.math.BigDecimal value.
Here is the code of program:
Output of program:
Set BigDecimal Example!
Database Table: bigdecimal
We have 1000s of tutorials on our website. Search Tutorials tutorials on our website.
Posted on: April 13, 2007 If you enjoyed this post then why not add us on Google+? Add us to your Circles