各位用过mysql中的longtext或者text的大神,小弟最近在学习使用ewebEditer和fckediter这种在线网页编辑工具,编辑完了会生成一串html源代码,我如何操作这些源代码,将其放入到我的数据库中呢??
有实现过的吗?最好给个例子哈,给一小段代码也行,谢谢了!

解决方案 »

  1.   

    用法和varchar的没什么大区别吧,将html源码转成字符串直接写入数据库就是,我一般用PreparedStatement类的setString和getString方法
      

  2.   

    给你个例子你看看就是了啊
    连接数据库package bao;import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;interface Lian {
    public String DBDRIVER = "com.mysql.jdbc.Driver";
        //public String DBDRIVER2 = "org.git.mm.mysql.Driver";//设置环境变量方法连接数据库
    public String DBURl = "jdbc:mysql://localhost:3306/test";
    public String DBUSER = "root";
    public String DBPASSWD = "313094983";//填写你的密码 public Connection getConn();
    };public class LianJdbc implements Lian {
    private Connection conn = null; public LianJdbc() {
    try {
    Class.forName(DBDRIVER);
    } catch (Exception e1) {
    e1.printStackTrace();
    }
    try {
    conn = DriverManager.getConnection(DBURl, DBUSER, DBPASSWD);
    } catch (SQLException e) {
    e.printStackTrace();
    }
    } public Connection getConn() {
    return this.conn;
    }
    };
    longtextpackage bao;
    import java.sql.*;
    import java.util.Scanner;
    import java.io.*;class Clob extends LianJdbc{
    private PreparedStatement pstm = null;
    //private ResultSet rs = null;
    public void insertClob() throws Exception{
    Connection conn = null;
    conn = super.getConn();
    String sql = "insert into userclob(name,note) values(?,?)";
    this.pstm =  conn.prepareCall(sql);
    File f = new File("d:"+File.separator+"1.txt");
    InputStream is = new FileInputStream(f);
    this.pstm.setString(1, "傲慢与偏见");
    this.pstm.setAsciiStream(2, is, (int)f.length());
    this.pstm.executeUpdate();
    this.pstm.close();
    conn.close();
    }
    public void selectClob() throws Exception{
    Connection conn = super.getConn();
    String sql = "select name,note from userclob where id = ?";
    this.pstm = conn.prepareStatement(sql);
    this.pstm.setInt(1, 1);
    ResultSet rs = this.pstm.executeQuery();
    if(rs.next()){
    String name = rs.getString(1);
    StringBuffer sb = new StringBuffer();
    System.out.println(name);
    InputStream is = rs.getAsciiStream(2);
    Scanner cin = new Scanner(is);
    cin.useDelimiter("\r\n");
    while(cin.hasNext()){
    sb.append(cin.next()).append("\n");
    }
    System.out.println(sb);
    is.close();
    }
    this.pstm.close();
    conn.close();
    }
    };class Blob extends LianJdbc{
    private Connection conn = null;
    private PreparedStatement pstm = null;
    //private ResultSet rs = null;
    public void insertBlob() throws Exception{
    this.conn = super.getConn();
    String sql = "insert into userblob(id,name,photo) values(?,?,?)";
    this.pstm = conn.prepareStatement(sql);
    this.pstm.setInt(1, 1);
    this.pstm.setString(2, "李冰冰");
    File f = new File("d:"+File.separator+"2.gif");
    InputStream is = new FileInputStream(f);
    this.pstm.setBinaryStream(3, is, f.length());
    this.pstm.executeUpdate();
    this.pstm.close();
    conn.close();
    }
    }
    public class CloBdemo{ /**
     * @param args
     */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    Blob b = new Blob();
    try {
    b.insertBlob();
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    }