Found 317 Articles for JDBC

How to write data into BLOB and CLOB type columns in a table using JDBC?

Smita Kapse
Updated on 30-Jul-2019 22:30:26

2K+ Views

CLOB stands for Character Large Object. in general, an SQL Clob is a built-in datatype which is used to store large amount of textual data. Using this datatype, you can store data up to 2, 147, 483, 647 characters. MYSQL database provides support Clob datatype TINYTEXT, TEXT, MEDIUMTEXT, LONGTEXT.The java.sql.Clob interface of the JDBC API represents the CLOB datatype. Since the Clob object in JDBC is implemented using an SQL locator, it holds a logical pointer to the SQL CLOB (not the data).Inserting Data into a column of Clob typeYou can insert a CLOB type value using the setCharacterStream() or, ... Read More

How to Read data from BLOB and CLOB type columns from a table using JDBC?

Anvi Jain
Updated on 30-Jul-2019 22:30:26

5K+ Views

Clob datatypeCLOB stands for Character Large Object. in general, an SQL Clob is a built-in datatype which is used to store large amount of textual data. Using this datatype, you can store data up to 2, 147, 483, 647 characters. MYSQL database provides support Clob datatype TINYTEXT, TEXT, MEDIUMTEXT, LONGTEXT.The java.sql.Clob interface of the JDBC API represents the CLOB datatype. Since the Clob object in JDBC is implemented using an SQL locator, it holds a logical pointer to the SQL CLOB (not the data).Reading Data from a column of datatype ClobYou can read CLOB value (character stream data) from a ... Read More

How to get the properties of a driver using JDBC?

Nishtha Thakur
Updated on 30-Jul-2019 22:30:26

603 Views

You can get the properties of a driver using the getPropertyInfo() method of the Driver interface.DriverPropertyInfo[] info = driver.getPropertyInfo(mysqlUrl, null);This method accepts a two parameters: A String variable representing the URL of the database, an object of the class Properties and, returns an array of the DriverPropertyInfo objects, where each object holds information about the possible properties of the current driver.From a DriverPropertyInfo object you can get the information such as name of the property, value of the property, description, choices and, if it is required or not, using its fields name, value, description, choices, required, respectively.DriverPropertyInfo[] info = driver.getPropertyInfo(mysqlUrl, ... Read More

How to retrieve binary data from a table using JDBC?

Anvi Jain
Updated on 30-Jul-2019 22:30:26

697 Views

SQL databases provide a datatype named Blob (Binary Large Object) in this, you can store large binary data like images.To retrieve binary (stream) values from a table JDBC provides a method called getBinaryStream() in the PreparedStatement interface.It accepts an integer representing the index of the column of the table and retrieves the binary data from it.You can retrieve binary data from a table using this method as shown below −FileInputStream fin = new FileInputStream("javafx_logo.jpg"); pstmt.setBinaryStream(3, fin);ExampleLet us create a table with name tutorials_data in MySQL using the CREATE statement as shown below −CREATE TABLE tutorials_data(    Name VARCHAR(255),    Type ... Read More

How to insert Binary data into a table using JDBC?

Nishtha Thakur
Updated on 30-Jul-2019 22:30:26

1K+ Views

SQL databases provide a datatype named Blob (Binary Large Object) in this, you can store large binary data like images.To store binary (stream) values into a table JDBC provides a method called setBinaryStream() in the PreparedStatement interface.It accepts an integer representing the index of the bind variable representing the column that holds values of type BLOB, an InputStream object holding the binary data and, inserts the given data in to the specified column.You can insert binary stream data into a table using this method as shown below −FileInputStream fin = new FileInputStream("javafx_logo.jpg"); pstmt.setBinaryStream(3, fin);ExampleLet us create a table with name ... Read More

What is the MySQL datatype to store DATALINK object in JDBC

Anvi Jain
Updated on 30-Jul-2019 22:30:26

301 Views

A DATALINK object represents an URL value which refers to an external resource (outside the current database/data source), which can be a file, directory etc..MySQL does not provide any separate datatype to store DATALINK/URL value you need to store using TEXT or VARCHAR datatypes as shown in the following query −CREATE TABLE tutorials_data (    tutorial_id INT PRIMARY KEY AUTO_INCREMENT,    tutorial_title VARCHAR(100),    tutorial_author VARCHAR(40),    submission_date date,    tutorial_link VARCHAR(255) );Following JDBC program establishes a connection with MYSQL database, creates a table with name tutorials_data. In this table we are creating a column with name tutorial_link which stores ... Read More

Example to create a table with all datatypes in MySQL using JDBC?

Nishtha Thakur
Updated on 29-Jun-2020 14:07:49

828 Views

Java provides supporting classes/datatypes to store all the MySQL datatypes, following is the table which list outs the respective java types for MySQL datatypes −MySQL TypeJava TypeCHARStringVARCHARStringLONGVARCHARStringNUMERICjava.math.BigDecimalDECIMALjava.math.BigDecimalBITbooleanTINYINTbyteSMALLINTshortINTEGERintBIGINTlongREALfloatFLOATdoubleDOUBLEdoubleBINARYbyte []VARBINARYbyte []LONGVARBINARYbyte []DATEjava.sql.DateTIMEjava.sql.TimeTIMESTAMPjava.sql.TiimestampExampleFollowing JDBC program creates a table with name sample with all the possible datatypes in MySQL −import java.sql.Connection; import java.sql.DriverManager; import java.sql.Statement; public class CreatingTable_AllDatatypes {    public static void main(String args[])throws Exception {       //Registering the Driver       DriverManager.registerDriver(new com.mysql.jdbc.Driver());       //Getting the connection       String mysqlUrl = "jdbc:mysql://localhost/sampledatabase";       Connection con = DriverManager.getConnection(mysqlUrl, "root", "password");       System.out.println("Connection ... Read More

How to create a MySQL table based on JDBC Result Set?

Smita Kapse
Updated on 30-Jul-2019 22:30:26

340 Views

The ResultSetMetadata class provides various methods that gives information about the current ResultSet object such as number of columns, name of the table, name of the column, datatype of the column etc…To prepare a CREATE query you need to get −Name of the table, using the getTableName() method.Column count, to iterate the columns using the getColumnCount() method.Name of the each column using the getColumnName() method.Data type of each column using the getColumnTypeName() method.Precision of each column using the getPrecision() method.ExampleLet us create a table with name customers in MySQL database using the CREATE query as shown below −CREATE TABLE Customers ... Read More

Write a program to get the list of all the supported datatypes in JDBC?

Anvi Jain
Updated on 30-Jul-2019 22:30:26

93 Views

The class named Types of the java.sql package contains the constants that represents the SQL datatypes. All these datatypes are represented by unique integer values.Retrieving the integer values from the Types classTo print all the class names and values of the constants in java.sql.Types class −Retrieve all the fields in Types class − The getFields() method of the class Class returns an array which holds all the fileds (public) of the class/interface represented by the current Class object.Using this method retrieve the array of fileds of the Types class as shown below −Field[] fields = java.sql.Types.class.getFields();Retrieve the name and value ... Read More

How to retrieve a DATALINK object from a table using JDBC?

Nishtha Thakur
Updated on 30-Jul-2019 22:30:26

108 Views

A DATALINK object represents an URL value which refers to an external resource (outside the current database/data source), which can be a file, directory etc..You can retrieve a DATALINK object an SQL table using the getURL() method of the PreparedStatement interface. This method accepts an integer value representing an index of the column in the ResultSet and returns the URL object in the specified index.ExampleLet us create a table with name tutorials_data in MySQL database using CREATE statement as shown below −CREATE TABLE tutorials_data (    tutorial_id INT PRIMARY KEY AUTO_INCREMENT,    tutorial_title VARCHAR(100),    tutorial_author VARCHAR(40),    submission_date date, ... Read More

Advertisements