Posts

Showing posts with the label File

How to generate excel sheet by using java

To generate an excel sheet by using java, we need to download the jxl.jar. This will help us to generate xls file by using predefined classes. For downloading jxl jar click here . This link will point to Maven repository from there you need to click on download button for downloading jar file. When jxl jar downloading will get complete, add the jar to project class path by following these steps. Right click on project --> goto properties --> select java build path --> select libraries --> click on add external jars button to browse downloaded jar path --> select jar and click on open button --> Ok. This jar file will provide few classes to design the excel sheet.  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 packag

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

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

Reading properties from a file with example

Reading properties from file, find list of files in a directory and find a year is leap year or not. These all example present in this post. Read properties from file:           Reading properties from properties(.properties) file is the major requirement in real-time applications. Here, we will come to know, how to read properties from file with an example explanation.           We will create one .properties file with the name of javaex.properties under src package and we will declare roleId's as key-value pairs. Like below, application.id.roleIds = ' 53 ',' 121 ',' 63 ',' 46 ',' 43 ',' 71 ',' 45 ',' 36 ',' 64 '           Here, application.id.roleIds is the Key to get the values, which  we will use in java class. The below program explains you how to read data from the properties file by using the key which you have declared in properties file. package com.javatbrains.