Powered by Ajaxy
Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Java: Save text file into a database

Java: Save  text file into a database

import java.io.File;
import java.io.FileReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
public class BD_CLOBs2
  public static void main(String[] args) throws Exception
    Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:Cours"
    	  , "myusername", "mypassword");
    String req = "INSERT INTO documents (name, price, file) VALUES (?, ?, ?)";
    PreparedStatement pStmt = conn.prepareStatement(req);
    pStmt.setString(1, "Staff");
    pStmt.setString(2, "1500$");
    File file = new File("C:/test.txt");
    FileReader reader = new FileReader(file);
    pStmt.setCharacterStream(3, reader, (int) file.length());

Users who found this page were searching for:

  • how to save a text in sql with java
  • how to save a java program to a text file
  • in java how to import textfiles and write text file into database
  • JDBC program to store a text file object into db
  • java sql save text db
  • import data from a text file into java db
  • sample java program to save text to a database
  • java program to save file to database
  • java how to save a text string to database

No comments yet.

Leave a Comment