0

I'm trying to store the contents of a text file onto a database. The text is no more than 1000 characters long. How do I do this?

1
  • Just confused as to how I should go about doing this Commented Jul 16, 2012 at 10:27

1 Answer 1

5

To save content of Text file into Database.

  1. Create a table with CLOB
  2. Use java.io.Reader to read the text file
  3. Use JDBC API (PreparedStatement) to execute INSERT statement.
String sql="INSERT INTO TableName (clobCol) VALUES (?)";
PrepareStatement ps=connection.prepareStatement(sql);
ps.setClob(1,readerObject);
Sign up to request clarification or add additional context in comments.

2 Comments

Just InputStream? Googling around I get C# results which imply that the steps are much more complicated, which is actually what's confusing me!
No, a Reader, you are dealing with character data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.