新手,还请各位多多指教

解决方案 »

  1.   

    pStatement.setBytes(7, sTitle.getFileByte());
      

  2.   

    public int insertOneRecord(SecondLevelTitle sTitle) {
        int result = 0;
        Connection con = null;
        PreparedStatement pStatement = null;    try {
          Date currentTime = new Date();
          SimpleDateFormat HMFromat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
          String strCurrentTime = HMFromat.format(currentTime);      con = ConnectionManager.getConnction();
          String strSql =
              "insert into SecondLevelTitle(Id,TitleName,FilePath,Creater,"
              + "CreatTime,ParentTitle,FileBytes) values(?,?,?,?,?,?,?)";
          pStatement = con.prepareStatement(strSql);
          pStatement.setInt(1, getNewId());
          pStatement.setString(2, sTitle.getTitleName());
          pStatement.setString(3, sTitle.getFilePath());
          pStatement.setString(4, sTitle.getCreater());
          pStatement.setString(5, strCurrentTime);
          pStatement.setInt(6, sTitle.getParentTitleId());
          pStatement.setBytes(7, sTitle.getFileByte());
          System.out.println(strSql);
          result = pStatement.executeUpdate();
        }
        catch (SQLException sqlE) {
          sqlE.printStackTrace();
        }
        finally {
          ConnectionManager.closeStatement(pStatement);
          ConnectionManager.closeConnection(con);
        }
        return result;
      }
      

  3.   

    使用blob的话,提醒你一下,这个是和使用什么数据库直接相关的,
    不同的数据库要用不同的方法,如果需要支持多种数据库,代码里面的分支是必不可少的
      

  4.   

    在数据库里面存文件名是最好的办法!新建java交流群,欢迎加入27455950
      

  5.   

    用<html:file
    把文件名存到数据库里,另外提供一个专门的IMG文件夹来存放图片。