".txt" to sql with JDBC

Ads
 

".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!!!

Ads









Related Tutorials/Questions & Answers:
".txt" to sql with JDBC
".txt" to sql with JDBC  how to insert ".txt" into sql result[BLOB] with JDBC
sql-jdbc
sql-jdbc  how to execute select query using prepared statement
Advertisements
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
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
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
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
Version of com.foundationdb>fdb-sql-layer-jdbc dependency
List of Version of com.foundationdb>fdb-sql-layer-jdbc dependency
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
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
JDBC Batch Example With SQL Select Statement
JDBC Batch Example With SQL Select Statement: In this example, we are discuss about SQL select statement with JDBC batch process. We will create SQL...;    static final String url = "jdbc
JDBC Connection code to connect servlet with SQL Server 2008
JDBC Connection code to connect servlet with SQL Server 2008  Please... support for JDBC 4.0. i try Avery thing but i m not success so please ans me . My... = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; static final String url = "jdbc:sqlserver://localhost
jdbc
jdbc define batch updates  define batch updates?exp   JDBC batch update is a collectively called when a group of SQL statements... than executing single SQL statement. For more information, visit the following
sql component
sql component  is sql package is the component of jdbc
JDBC
JDBC save a data in the database  I need a code to save a data... between java and mysql using JDBC and saves the data into the database. import... con = null; String url = "jdbc:mysql://localhost:3306/"; String db
JDBC
JDBC code to save a data in the database  I need a code to save... the connection between java and mysql using JDBC and saves the data into the database...!"); Connection con = null; String url = "jdbc:mysql://localhost:3306/"; String db

Ads