【问题标题】:How to insert HTML in MySQL DB using Java?如何使用 Java 在 MySQL DB 中插入 HTML?
【发布时间】:2011-03-30 02:10:00
【问题描述】:

我们如何使用 Java 将网页的完整 HTML 插入到我的表格中?

【问题讨论】:

  • HTML 不属于数据库。你应该重新考虑那个设计。

标签: java mysql html


【解决方案1】:

如果您将完整的 HTML 页面放入数据库中,您可能需要考虑压缩该字段。应该可以节省大量空间...

【讨论】:

    【解决方案2】:

    执行以下操作:

    以某种方式将页面的 HTML 放入字符串变量中:

    String fullHtml = "";
    

    创建带有文本字段的表格

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

    使用 JDBC 插入 html 内容:

    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();
    

    你已经完成了。

    【讨论】:

      【解决方案3】:

      在 MySQL 中使用 text 类型。然后使用简单的Statement / PreparedStatement 插入文本。

      我的建议是在数据库之外有一个 html 模板,并用从数据库获得的特定数据填充它。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2010-10-04
        • 2017-06-16
        • 2014-10-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多