- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 317 Articles for JDBC
4K+ Views
Grouping a set of INSERT Statements and executing them at once is known as batch insert.Batch inserts using PreparedStatement objectTo execute a batch of insert statements using the PreparedStatement object −Create a PreparedStatement − Create a PreparedStatement object using the prepareStatement() method. Pass the Insert query with place holders “?” instead of values as a parameter to this method.PreparedStatement pstmt = con.prepareStatement("INSERT INTO Sales VALUES (?, ?, ?, ?, ?)");Set the values to the place holders − Using the setXXX() methods (setInt(). SetString(), setFloat() etc…) set the values to the place holders in the PrepareStatement as −pstmt.setString(1, "KeyBoard"); pstmt.setString(2, "Amith"); ... Read More
865 Views
To insert records into a table that contains a decimal value using PreparedStatement you need to −Register the driver − Register the driver class using the registerDriver() method of the DriverManager class. Pass the driver class name to it, as parameter.Establish a connection − Connect ot the database using the getConnection() method of the DriverManager class. Passing URL (String), username (String), password (String) as parameters to it.Create Statement − Create a PreparedStatement object using the prepareStatement() method of the Connection interface. Pass the INSERT query with place holders to this method in String format as a parameter.PreparedStatement pstmt = con.prepareStatement("INSERT ... Read More
547 Views
An unpacked floating-point number that cannot be unsigned. In the unpacked decimals, each decimal corresponds to one byte. Defining the display length (M) and the number of decimals (D) is required. NUMERIC is a synonym for DECIMAL.To define a column with a decimal value as datatype follow the syntax given below −column_name DECIMAL(P, D);Where −P is the precision representing the number of digits (range 1 to 65)D is the scale representing the number of digits after the decimal point.Note − in MySQL D should be describe customers; +------------+---------------+------+-----+---------+-------+ | Field | Type | ... Read More
3K+ Views
To execute a statement with Where clause using PreparedStatement. Prepare the query by replacing the value in the clause with place holder “?” and, pass this query as a parameter to the prepareStatement() method.String query = "SELECT * FROM mobile_sales WHERE unit_sale >= ?"; //Creating the PreparedStatement object PreparedStatement pstmt = con.prepareStatement(query);Later, set the value to the place holder using the setXXX() method of the PreparedStatement interface.pstmt.setInt(1, 4000); ResultSet rs = pstmt.executeQuery();ExampleLet us create a table with name mobile_sales in MySQL database using CREATE statement as shown below −CREATE TABLE mobile_sales ( mobile_brand VARCHAR(255), unit_sale INT );Now, we ... Read More
558 Views
The java.sql.Types class represents the SQL datatype in integer format. The valueOf() method of the enumeration JDBCType accepts an integer value representing the java.sql.Type and, returns the JDBC type corresponding to the specified value.ExampleLet us create a table with name MyPlayers in MySQL database using CREATE statement as shown below −CREATE TABLE MyPlayers( ID INT, First_Name VARCHAR(255), Last_Name VARCHAR(255), Date_Of_Birth date, Place_Of_Birth VARCHAR(255), Country VARCHAR(255), PRIMARY KEY (ID) );Following JDBC program establishes connection with the MySQL database retrieves the contents of the MyPlayers table into a ResultSet object, obtains its metadata, obtains the column ... Read More
421 Views
Yes, in Oracle you can store and retrieve a boolean value into a table for a column with VARCHAR2 datatype.If you do so, the true and false values are stored as 1 and 0 and the retrieved as same (respectively).ExampleLet us create a table with name sampleTable in the Oracle database Using CREATE statement as −CREATE TABLE sampleTable( ID INT, ProductName VARCHAR (20) NOT NULL, CustomerName VARCHAR (20) NOT NULL, IsBillDue VARCHAR (20) NOT NULL, DeliveryDate date, Price INT, Location varchar(20) );The column IsBillDue specified whether bill paid.Following JDBC program establishes the connection ... Read More
3K+ Views
The IN clause in MYSQL database is used to specify the list of parameters in a query.For example, you need to retrieve contents of a table using specific IDs you can do so using the SELECT statement along with the IN clause as −mysql> SELECT * from sales where ID IN (1001, 1003, 1005); +------+-------------+--------------+--------------+--------------+-------+------------+ | ID | ProductName | CustomerName | DispatchDate | DeliveryTime | Price | Location | +------+-------------+--------------+--------------+--------------+-------+------------+ | 1001 | Key-Board | Raja | 2019-09-01 | 11:00:00 | 8500 | Hyderabad ... Read More
198 Views
Creating an Encrypted LOB(CLOB or, BLOB)Oracle database from 11g onwards provides SecureFiles feature to encrypt the Large object files (LOBs). You can create a secure file using the SECUREFILE keyword as −CREATE TABLE table_name ( myClob CLOB ) LOB(myClob) STORE AS SECUREFILE;You can encrypt a secured file using Encrypt option for encryption you can use 3DES168 or, AES128 or, AES192 or, AES256 algorithm.CREATE TABLE encrypt_tab ( myClob CLOB ) LOB(myClob) STORE AS SECUREFILE encrypt_lob( ENCRYPT USING 'AES256' );
4K+ Views
If you insert records into a table which contains auto-incremented column, using a Statement or, PreparedStatement objects.You can retrieve the values of that particular column, generated by them object using the getGeneratedKeys() method.ExampleLet us create a table with name sales in MySQL database, with one of the columns as auto-incremented, using CREATE statement as shown below −CREATE TABLE Sales( ID INT PRIMARY KEY AUTO_INCREMENT, ProductName VARCHAR (20), CustomerName VARCHAR (20), DispatchDate date, DeliveryTime time, Price INT, Location VARCHAR(20) );Retrieving auto-generated values (PreparedStatement object)Following JDBC program inserts 3 records into the Sales table (created above) ... Read More
1K+ Views
While creating a table, in certain scenarios, we need values to column such as ID, to be generated/incremented automatically. Various databases support this feature in different ways.In MySQL database you can declare a column auto increment using the following syntax.CREATE TABLE table_name( ID INT PRIMARY KEY AUTO_INCREMENT, column_name1 data_type1, column_name2 data_type2, column_name3 data_type3, column_name4 data_type4, ............ ........... );While inserting records in a table there is no need to insert value under the auto-incremented column. These will be generated automatically.Setting the initial valueBy default, the initial value of the auto-incremented column will be 1. You ... Read More