Posts

Showing posts with the label Database

Retrieve File from table by using JDBC with example

To retrieve file from table by using the JDBC here is the example. Let's, come to the first to database as MySQL and table name as myFiles and column name as file_type. These table data we have already inserted files in previous program. Now, we should retrieve from the  ResultSet  using  getClob()  method. 1 Clob file = rs . getClob (); Here,  getClob()  method retrieving data from column and storing it into  Clob  class object as file. Use  getCharacterStream()  method which will available under the  Clob  object, it also gets the file data from  Clob  object into a reader object. 1 Reader r = file . getCharacterStream (); Here, we are reding data from Reader object r and writing it into  FileWriter  which stores it into a file as  D:/OutPutFile.txt . Registering the Driver and creating Connection and Statements are same in the all JDBC programs. In query we are fetching only file column from table.  1 2 3 4 5 6 7 8 9 10 11

Store file into table by using JDBC with example

To store large data files or text files into database table, we will use CLOB (Charecter Large Object) datatype of SQL . By using CLOB it is possible to save entire text book or a file or resume into a column of data table. If your using MySQL database instead of CLOB use LONGTEXT to save file into datatable. For saving files into a data table, we need to create one table which will contains a column type as CLOB to store files. Here, is the query to create a data table. 1 2 3 4 create table myfiles( file_id int ( 10 ), file_name varchar ( 30 ), file_type LONGTEXT); Once table creation completes, these table contains the 3 columns one is file_id represents the file id, file_name represents the name of the file and finally file_type will get save entire file into the table column. Now, we will move to write a JDBC program which will saves the file into the newly creating table. Here is the JDBC program, 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

How to retrieve data from table by using JDBC with example

To retrieve data from mysql data table by using jdbc, we need to confirm weather which table data we need to retrieve. To confirm open your mysql and view all database names by using the ' show databases ' commands in mysql. Then select which is your database name from showing list of database names, by using the ' use <database name> ' command in mysql. Then we need to see all your existing tables by executing the ' show tables ' command. This command gives you the list of existing tables in your selected database. You need to use existing table only you can follow with that. But, here we will see with entirely new which is not existing in mysql database. Now, We will create simple mysql table with minimal columns. create table emp(eno integer(10), ename varchar(30), sal float); The above command creates a new table, we will move further to insert records into emp table by executing the insert which we mentioned in the below.

Serialization and deserialization in java with examples

Serialization and Deserialization is one of the commonly used concept in java to store object in any other location like, File, DB, Cloud,...etc and vice versa is called as Deserialization. In other words, Java provides a mechanism called Serialization to persist Java object into a file, database, network, process or any other system. Serialization makes object into an ordered or Serialized stream of bytes. That includes the object data as well as object type of data stored. Before moving further in Serialization and Deserialization in java, have a look at Input and Output streams. If you need to make your object as Serialized, the object class should be implemented from Serializable interface. Serializable is one of the interface called as marker interface in java. Marker interface is nothing but an interface which has no methods or fields to implement but it will do some functionality. Serializable interface is part of java.io package in java. ObjectOutputStream and ObjectInputS