0

How can we insert full HTML of a webpage into my table using Java?

1
  • 1
    HTML doesn't belong in a database. You should rethink that design. Commented Aug 15, 2010 at 14:07

3 Answers 3

3

Do what follows:

Get your page's HTML somehow into a String variable:

String fullHtml = "";

Create a table with a text field

create table your_html_container (
     id int primary key autoincrement,
     content text not null
);

Insert html content using JDBC:

Connection conn = DriverManager.getConnection(connectionURL, user, password);
PreparedStatement pstmt = 
    conn.prepareStatement("insert into your_html_container (content) values (?)");
pstmt.setString(1, fullHtml); // this is your html string from step #1
pstmt.executeUpdate();
pstmt.close();
conn.close();

You are done.

Sign up to request clarification or add additional context in comments.

Comments

1

Use the text type in MySQL. Then use a simple Statement / PreparedStatement to insert the text.

What I'd suggest though is to have an html template outside the DB, and fill it with specific data obtained from the DB.

Comments

0

If you are putting full HTML pages in the DB, you may want to look into zipping the field. Should get pretty substantial space savings...

Comments

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.