Posts

Showing posts with the label SQL

structured query language

SQL stands for 'Structured Query Language', which will use to interact with database to perform Create, Read, Update, Delete operations on database tables. SQL is also a language, where as SQL server is a database. To work on SQL, a Database software RDBMS is required. RDBMS stands as Relation Data Base Management System. SQL is not case sensitive. If your using Oracle SQL, you may get the below errors. If your using MySQL, you forget about this errors and move further for commands. Troubleshooting Oracle Error1. The account is locked Steps to rectify the error Login as username - 'system' & password - 'manager' or password - 'tiger' SQL> show user;        User is 'SYSTEM'         SQL> ALTER user<username> account unblock;        Ex:  ALTER  user scott account unlock;        User altered.        To close/exit the SQL command prompt usually we will use EXIT command.        SQL> exit; Error2. TNS: prot

JDBC interview questions and answers

1. What is the JDBC? A. Java Database Connectivity (JDBC) is a standard Java API to interact with relational database form Java. JDBC has set of classes and interfaces which can use from Java application and talk to database without learning RDBMS details and using Database specific JDBC Drivers. 2. What are the new features added to JDBC 4.0? A. The major features added in JDBC 4.0 includes:        • Connection management enhancements        • Support for RowId SQL type        • provides SQL DataSet implementation using annotations        • SQL exception handling enhancements        • SQL XML support 3. Explain basic steps in writing a java program using JDBC? A. JDBC makes the interaction with RDBMS simple and interactive. When a java application needs to access database, Loads RDBMS specific JDBC driver because this driver actually communicates with the database. Opens the connection to database which is then used to send SQL statements and get resul

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