".txt" to sql with JDBC

".txt" to sql with JDBC

how to insert ".txt" into sql result[BLOB] with JDBC?

View Answers

April 5, 2011 at 3:32 PM

import java.io.*;
import java.sql.*;
class InsertFileDataAsBLOB 
{
    public static void main(String[] args) 
    {
      try{
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
        File f = new File("C:/hello.txt");
        PreparedStatement psmnt = connection.prepareStatement("insert into file(file_data) values(?)");
        FileInputStream fis = new FileInputStream(f);
        psmnt.setBinaryStream(1, (InputStream)fis, (int)(f.length()));
        int s = psmnt.executeUpdate();
        if(s>0){
        System.out.println("Inserted successfully !");
        }
        else{
        System.out.println("Error!");
        }
      }
      catch(Exception e){
          e.printStackTrace();
    }
  }
}

April 5, 2011 at 7:54 PM

Thanks!!!









Related Tutorials/Questions & Answers:
".txt" to sql with JDBC
".txt" to sql with JDBC  how to insert ".txt" into sql result[BLOB] with JDBC
How to import txt file using SQL
How to import txt file using SQL  Hai, I have a log file in .txt... particular words and insert onto a table using SQL. I want the output of the table... is it possible in SQL, If possible tell the script. **** Notification : 8020374
Advertisements
sql - JDBC
key constraints in SQL server  Does SQL have a FOREIGN KEY constraints in a Table
sql - JDBC
SQL joins queries   Hi, can anyone give me the couple of SQL joins queries with examples
sql-jdbc
sql-jdbc  how to execute select query using prepared statement
sql - JDBC
://www.roseindia.net/jdbc/jdbcconnectivity.shtml You will find the solution. Thanks
Sql - JDBC
SQL Statement and prepared statement  What is Statement and prepared statement in SQL  Statement and prepared statement are the interfaces declared in JAVA.SQL.While you connecting to a database these are required.If
jdbc & sql related project - JDBC
jdbc & sql related project  code using jdbc,odbc,swing,MySql classes to create front-end of any jdbc that allows the user to select any database from a list and execute any sql query related to the selected database e.g
creating jdbc sql statements - JDBC
creating jdbc sql statements  I had written the following program...=DriverManager.getConnection("jdbc:odbc:second"); stmt=con.createStatement...)   Hi friend, i think, connection problem. i am sending jdbc
Connectivity with sql in detail - JDBC
Connectivity with sql in detail  Sir/Madam, I am unable to connect the sql with Java. Please tell me in detail that how to connect...; String url = "jdbc:mysql://localhost:3306/"; String dbName
JDBC connection and SQL Query - JDBC
JDBC connection and SQL Query  Hi, I'm reading a all files one after the other in a directory in java. storing the values in an array of string each time. Now I'm trying to execute a query to insert those values into an oracle
sql query - JDBC
sql query  I need a SQL query to add data into database
Connections with MicroSoft SQL - JDBC
Connections with MicroSoft SQL  How to Connect Java and MS SQL?? Actually i used below code i got SQLException and class not found... import...; Statement st = null; ResultSet rs = null; String url = "jdbc
My sql - JDBC
,emp_vertical,emp_supervisor. i need a JDBC program with driver mangager... out. i need insert and update queries.  Hi friend, For JDBC...://www.roseindia.net/jdbc/jdbc-mysql/SelectRecords.shtml http://www.roseindia.net/jdbc
Connectivity with sql in detail - JDBC
Connectivity with sql in detail  Sir/Madam, I am unable to connect the sql with Java. Please tell me in detail that how to connect. Thankyou
Connectivity with sql in detail - JDBC
Connectivity with sql in detail  Sir/Madam, I am unable to connect the sql with Java. Please tell me in detail that how to connect. Thankyou
jdbc sql exception.
jdbc sql exception.  import java.sql.*; import java.io.*; class...("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc..."); Connection con=DriverManager.getConnection("jdbc:odbc:student
SQL QUERY - JDBC
SQL QUERY  I m running a query using apache tomcat the sql query is on adding an employee in the database whenever i click on add after inserting the values i am getting a java.lang.nullpointer exception
java-sql - JDBC
java-sql  how to convert excel file into sql database usin java programming
jdbc odbc sql server exception
jdbc odbc sql server exception  Hi, I am trying to use sql server with java jdbc odbc but I am getting this exception java.sql.SQLException: [Microsoft][SQL Server Native Client 10.0][SQL Server]Incorrect syntax near '@P1
Help on JDBC and my SQL 5 database - JDBC
Help on JDBC and my SQL 5 database  Dear Sir, I had create a statement for the JDBC as shown below: try... the connection c = DriverManager.getConnection ("jdbc:mysql
JDBC- SQL spatio-temporal query
JDBC- SQL spatio-temporal query  Any one give me a JDBC sql query for my spatio temporal query? Trajectory table OBJID PLACE 7 H 8 Q 9 W 10... as shown in above. I want a spatio-temporal query using JDBC-SQL to retrieve
JDBC- SQL spatio-temporal query
JDBC- SQL spatio-temporal query  Any one give me a JDBC sql query for my spatio temporal query? Trajectory table OBJID PLACE 7 H 8 Q 9 W 10... as shown in above. I want a spatio-temporal query using JDBC-SQL to retrieve
SQL STATEMENT in JDBC in NETBEANS IDE
SQL STATEMENT in JDBC in NETBEANS IDE  Iam using NETBEANS IDE. Iam developing a bank application. Using JDBC in SERVLETS For the withdraw function, "bal" and "ano" are user inputs when i wrote like, st.executeQuery("UPDATE
upload SQL BLOB and CLOB - JDBC
upload SQL BLOB and CLOB  Please explain upload SQL BLOB and CLOB
Version of com.foundationdb>fdb-sql-layer-jdbc dependency
List of Version of com.foundationdb>fdb-sql-layer-jdbc dependency
UNICODE or SQL statement issue - JDBC
UNICODE or SQL statement issue  Hi again............ I have got something new that........... i was using MS Access as the database with my... nothing ...... I had also change my backhand to SQL SERVER but retrieves same
Getting the Records in PL/SQl between Date Ranges - JDBC
Getting the Records in PL/SQl between Date Ranges  Getting the records Between the Dates in PL/SQL Database by using JDBC and display through JSP
sql - JDBC
sql - JDBC
jdbc - SQL
jdbc - SQL
DataBase connectivity in java with Microsoft sql server2000 - JDBC
DataBase connectivity in java with Microsoft sql server2000  How i can achieve database connectivity with Microsoft sql server2000 in my java source code
Maven Dependency fdb-sql-layer-jdbc >> 1.9-1-jdbc4
You should include the dependency code given in this page to add Maven Dependency of com.foundationdb >> fdb-sql-layer-jdbc version1.9-1-jdbc4 in your project
Maven Dependency fdb-sql-layer-jdbc >> 1.9-1-jdbc41
You should include the dependency code given in this page to add Maven Dependency of com.foundationdb >> fdb-sql-layer-jdbc version1.9-1-jdbc41 in your project
Maven Dependency fdb-sql-layer-jdbc >> 1.9-3-jdbc4
You should include the dependency code given in this page to add Maven Dependency of com.foundationdb >> fdb-sql-layer-jdbc version1.9-3-jdbc4 in your project
Maven Dependency fdb-sql-layer-jdbc >> 1.9-3-jdbc41
You should include the dependency code given in this page to add Maven Dependency of com.foundationdb >> fdb-sql-layer-jdbc version1.9-3-jdbc41 in your project
Maven Dependency fdb-sql-layer-jdbc >> 1.9-4-jdbc4
You should include the dependency code given in this page to add Maven Dependency of com.foundationdb >> fdb-sql-layer-jdbc version1.9-4-jdbc4 in your project
Maven Dependency fdb-sql-layer-jdbc >> 1.9-4-jdbc41
You should include the dependency code given in this page to add Maven Dependency of com.foundationdb >> fdb-sql-layer-jdbc version1.9-4-jdbc41 in your project
Maven Dependency fdb-sql-layer-jdbc >> 1.9-5-jdbc4
You should include the dependency code given in this page to add Maven Dependency of com.foundationdb >> fdb-sql-layer-jdbc version1.9-5-jdbc4 in your project
Maven Dependency fdb-sql-layer-jdbc >> 1.9-5-jdbc41
You should include the dependency code given in this page to add Maven Dependency of com.foundationdb >> fdb-sql-layer-jdbc version1.9-5-jdbc41 in your project
Maven Dependency fdb-sql-layer-jdbc >> 2.0-0-jdbc4
You should include the dependency code given in this page to add Maven Dependency of com.foundationdb >> fdb-sql-layer-jdbc version2.0-0-jdbc4 in your project
Maven Dependency fdb-sql-layer-jdbc >> 2.0-0-jdbc41
You should include the dependency code given in this page to add Maven Dependency of com.foundationdb >> fdb-sql-layer-jdbc version2.0-0-jdbc41 in your project
Maven Dependency fdb-sql-layer-jdbc >> 2.0-1-jdbc4
You should include the dependency code given in this page to add Maven Dependency of com.foundationdb >> fdb-sql-layer-jdbc version2.0-1-jdbc4 in your project
Maven Dependency fdb-sql-layer-jdbc >> 2.0-1-jdbc41
You should include the dependency code given in this page to add Maven Dependency of com.foundationdb >> fdb-sql-layer-jdbc version2.0-1-jdbc41 in your project
Maven Dependency fdb-sql-layer-jdbc >> 2.1-0-jdbc4
You should include the dependency code given in this page to add Maven Dependency of com.foundationdb >> fdb-sql-layer-jdbc version2.1-0-jdbc4 in your project
Maven Dependency fdb-sql-layer-jdbc >> 2.1-0-jdbc41
You should include the dependency code given in this page to add Maven Dependency of com.foundationdb >> fdb-sql-layer-jdbc version2.1-0-jdbc41 in your project
Database connection sql server 2005 - JDBC
Database connection sql server 2005  Hi all i am developing an application in struts and i need to connect database for that application using sql server 2005.. can anyone tell me how to make database connection ..plz help me
JDBC Batch Example With SQL Insert Statement
JDBC Batch Example With SQL Insert Statement: In this tutorial, we are discuss about insert SQL statement with the jdbc batch. First of all, we...;com.mysql.jdbc.Driver"); connection = DriverManager.getConnection ("jdbc
JDBC Batch Example With SQL Update Statement
JDBC Batch Example With SQL Update Statement: In this tutorial, we are discuss about update SQL statement with the jdbc batch. Now we will create a java...;com.mysql.jdbc.Driver"); connection = DriverManager.getConnection( "jdbc:mysql

Ads