【问题标题】:save the content from a jtextpane in derby?将内容从 derby 中的 jtextpane 保存?
【发布时间】:2014-01-05 00:49:18
【问题描述】:

如何在 derby 中保存 jtextpane 中的内容? 我正在编写一个具有 jtetxpane 和 derby db 的软件,当我将文本保存为字符串时,在阅读它的那一刻,它会丢失所有字体样式,如粗体或斜体。 我将字符串保存在preparedStatemend.so中如何将文本保存在derby中?我正在考虑一个blob,那么如何从jtextpane中保存一个blob并阅读它?或者我怎样才能保存它? 我该如何解决? 对不起,如果我的英语不好。

插入:

        try {
        String driver = "org.apache.derby.jdbc.EmbeddedDriver";
        String dbName = "bdprueba";
        String dbParam = "create=true"; //la base de datos se creará si no existe todavía
        String connectionURL = "jdbc:derby:" + dbName + ";" + dbParam;
        String sql="insert into persona (texto) values(?)";

        Connection conn = DriverManager.getConnection(connectionURL);
        PreparedStatement st = conn.prepareStatement(sql);
        st.setString(1, texto.getText());
        st.executeUpdate();
        conn.close();
    } catch (SQLException ex) {
        Logger.getLogger(Editor.class.getName()).log(Level.SEVERE, null, ex);
    } catch (BadLocationException ex) {
        Logger.getLogger(Editor.class.getName()).log(Level.SEVERE, null, ex);
    }

选择:

    try {
        String driver = "org.apache.derby.jdbc.EmbeddedDriver";
        String dbName = "bdprueba";
        String dbParam = "create=true"; 
        String connectionURL = "jdbc:derby:" + dbName +"" ;
        Class.forName(driver);
        Connection conn =  DriverManager.getConnection(connectionURL); 
        Statement st = conn.createStatement();
        ResultSet rs =  st.executeQuery("select texto from persona");
        while(rs.next())
        {      
            texto.setText(rs.getString("Texto"));            
        }
    } catch (ClassNotFoundException ex) {
        Logger.getLogger(Editor.class.getName()).log(Level.SEVERE, null, ex);
    } catch (SQLException ex) {
        Logger.getLogger(Editor.class.getName()).log(Level.SEVERE, null, ex);
    }

青草

谢谢你们

【问题讨论】:

  • 它会丢失所有字体样式,例如粗体或斜体。一切都取决于如何将荧光笔应用于文档

标签: java swing jdbc derby jtextpane


【解决方案1】:

您能否保存字符串,然后在保存并比较两个字符串后立即读取它?如果它们相同,则问题不在于数据库部分。

我会检查目标 JtextPane 的编辑器工具包。它必须与源 JTextPane 中的相同。如果字符串不同,那就是数据库问题。

查看http://www.java2s.com/Code/Java/Database-SQL-JDBC/Saveimagetoderbydatabase.htm 示例。您可以存储文本(字符串的字节)而不是图像。

【讨论】:

    【解决方案2】:

    尝试使用文档而不是 getText()

    jtextpane.getDocument()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-19
      相关资源
      最近更新 更多