Posts

Showing posts with the label MySQL

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

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.