Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Programming Articles - Page 2014 of 2505
3K+ Views
CachedRowSet interface does not provide any methods to determine whether a particular column exists.Therefore, to find whether a RowSet contains a specific column, you need to compare the name of each column in the RowSet with the required name. To do so −Retrieve the ResultSetMetaData object from the RowSet using the getMetaData() method.ResultSetMetaData meta = rowSet.getMetaData();Get the number of columns in the RowSet using the getColumnCount() method.int columnCount = meta.getColumnCount();The getColumnName() method returns the name of the column of the specified index. Using this method retrieve the column names of the RowSet from index 1 to column count and compare ... Read More
4K+ Views
One way to get the name of the underlying database you have connected with is by invoking the getDatabaseProductName() method of the DatabaseMetaData interface. This method returns the name of the underlying database in String format.Therefore, to retrieve the name of your current database using Java code −Retrieve the DatabaseMetaData object of the current Connection using the getMetaData() method.//Retrieving the meta data object DatabaseMetaData metaData = con.getMetaData();Then, get the product name of the underlying database you have connected to using the getDatabaseProductName() method of the DatabaseMetaData interface as −//retrieving the name of the database String product_name = metaData.getDatabaseProductName();ExampleFollowing JDBC program ... Read More
6K+ 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
1K+ 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
832 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
827 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
656 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
4K+ 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
388 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' );
5K+ 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