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
{filelink=7048}

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");
    conn.setAutoCommit(false);
    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());
    pStmt.execute();
    conn.commit();
    reader.close();
    conn.close();
  }
}

Users who found this page were searching for:

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

No comments yet.

Leave a Comment