tags:

views:

43

answers:

3

Hey Friends,

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

+1  A: 

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.

Bozho
+3  A: 

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.

Pablo Santa Cruz
A: 

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...

bwawok