Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners ".txt" to sql with JDBC

Have Programming Question? Ask it here!
 
 
 


sk
".txt" to sql with JDBC
2 Answer(s)      3 years and 4 months ago
Posted in : Java Beginners


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


Advertisement
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
SQL joins queries   Hi, can anyone give me the couple of SQL joins queries with examples
sql - JDBC
key constraints in SQL server  Does SQL have a FOREIGN KEY constraints in a Table
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
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
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
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
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
Thread for reading txt file
Thread for reading txt file  how to use 3 thread to read 3 txt file? To create three threads for reading the file and three threads for getting the strings out of the queue and printing them. thanks
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
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
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
txt to cvs format
txt to cvs format  i am writing a simple program that read a text file from one directory and writes an new one in cvs format in another one. I am...; /*this program reads files from inpath and writes them to outpath as a single txt
Convesion of txt file to doc file.??????
Convesion of txt file to doc file.??????  how to convert text file to doc file using java
Adding .txt files in a given directory
Adding .txt files in a given directory  I want to read number of XML... tag value as one .txt file in a given directory? I have extracted tag values but plz help me how can I save each body tag as one .txt file and add in a directory
Backup Into txt File
Backup Into txt File       Backup Into txt File is used to put the backup file from a ... illustrate an example from 'Backup Into txt File'. To understand this example
Uploading and download pdf or .txt file.
Uploading and download pdf or .txt file.  I want admin user to upload pdf file into database and the users can download those pdf format from database
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
Convert pdf to rtf and txt - XML
Convert pdf to rtf and txt  Can we convert PDF to RTF and TXT, and how?  Hi Friend, Try the following codes: 1)Convert PDF to RTF import java.io.*; import java.util.*; import com.lowagie.text.*; import
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
Backup selected records into txt file
Backup selected records into txt file       Backup selected records into txt file is used to copies... into txt file. To restore the selected backup records into txt file, we create
how to change file from .txt to .mat(matrix)
how to change file from .txt to .mat(matrix)  i have a big file.txt and i want to change this file to file.mat(matrix) ...this is in windows not on any os ..thx if u answering quickly please
Shifting txt file to database - Java Beginners
Shifting txt file to database   Question Details: I want to shift data from txt file to Database. The data is written in the following text format. Record No. = 0001 Name : Abdul Rauf Designation
Backup Into txt File
Backup Into txt File       Backup Into txt File is used to put the backup file from... The Tutorial illustrate an example from 'Backup Into txt File
sql component
sql component  is sql package is the component of jdbc
convert .txt file in .csv format - Java Beginners
convert .txt file in .csv format  Dear all, I hope you are doing good. I am looking to convert .txt file in .csv format. The contents might have different names and values. e.g. start: id:XXXX name:abc address:xyz
 

 

 

DMCA.com