Programming Articles - Page 2553 of 3363

How to retrieve binary data from a table using JDBC?

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

998 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

2K+ 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

453 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

Ways to print escape characters in python

Hafeezul Kareem
Updated on 30-Jul-2019 22:30:26

4K+ Views

In this article, we are going to see how we can print the escape characters in Python. I think you know what escape characters are? Let's see what escape characters for those who don't know are?Escape characters are used for the individual meanings in strings. If we want to include a new line, tab space, etc., in strings, we can use these escape characters. Let's see some examples.Example Live Demo## new line new_line_string = "HiHow are you?" ## it will print 'Hi' in first line and 'How are you?' in next line print(new_line_string)OutputIf you run the above program, it will ... Read More

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

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

1K+ 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

499 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

Ways to increment a character in python

Hafeezul Kareem
Updated on 29-Jun-2020 13:48:16

12K+ Views

In this tutorial, we are going to see different methods to increment a character in Python.TypecastingLet's first see what happens if we add an int to char without typecasting.Example Live Demo## str initialization char = "t" ## try to add 1 to char char += 1 ## gets an errorIf you execute above program, it produces the following result −TypeError          Traceback (most recent call last) in ()       3     4 ## try to add 1 to char ----> 5 char += 1 ## gets an error TypeError: must be str, not intTo ... Read More

What are the differences between JTextField and JTextArea in Java?

Alshifa Hasnain
Updated on 11-Apr-2025 22:24:05

5K+ Views

The main difference between JTextField and JTextArea in Java is that a JTextField allows entering a single line of text in a GUI application while the JTextArea allows entering multiple lines of text in a GUI application. JTextField The following are the key characteristics of JTextField in Java: A JTextFeld is one of the most important components that allow the user to an input text value in a single line format. A JTextField will generate an ActionListener interface when we trying to enter some input inside it. The JTextComponent is a superclass of JTextField that provides a common set ... 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

206 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

230 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