第九大陆在服务器上未找到文件,急問一問題 FileInputStream方法,老是提示找不到指定文件!...

#5

public void addClob() {

try {

//取得舊表得ID列表

// ResultSet rsTmp=DoSQL.Select("zd2_T_NEWS2","COL007",false);

//String [] idList = SQLAI.getPrimaryKey("fj_xt_zd2_T_news");

String[] idList = this.getContent();

String titleList[] = this.getTitle();

String newsID [] = this.getNewsID();

//--開始讀取大文本到數據庫--

int countReplain = 0; //統計導入的大文件個數

for (int i = 0; i 

//--初始化數據庫連接--

java.sql.Connection con = Dbconn.pubGetCon();

con.setAutoCommit(false);

java.sql.Statement st = con.createStatement();

PreparedStatement psSel = null;

PreparedStatement ps = null;

ResultSet rs = null;

//構造文件名

String path = "c:\\abc\\" + idList[i].trim() + ".txt";

//--取得數據庫重中的大文本字段--

int id = i;

rs = null;

/* 查詢此CLOB對象並鎖定 */

String sql =

"insert into t_news_message2 (id,title,content) values (?,?,empty_clob())";

String selectSql =

"SELECT content FROM t_news_message2 WHERE ID="

+ id

+ " FOR UPDATE";

String sqlUpdate =

"update "

+ "t_news_message"

+ " SET content=? where id = "

+ id;

psSel = con.prepareStatement(sql);

psSel.setInt(1, id);

psSel.setString(2, titleList[i]);

psSel.executeUpdate();

rs = st.executeQuery(selectSql);

rs.next();

CLOB clob = (CLOB) rs.getClob("content");

//----

BufferedReader in = null;

//BufferedWriter out=null;

try {

//-- 向CLOB對象中寫入數據 --

//out = new BufferedWriter(clob.getCharacterOutputStream());

in = new BufferedReader(new FileReader(path));

if (in != null) {

String s;

String sAll = new String("");

if(this.getCountNewsID(newsID[i])>0)

{

sAll = sAll + this.getPicUrl(newsID[i]) ;

}

while ((s = in.readLine()) != null) {

sAll = sAll + "    "+ s + "
";

}

System.out.println(sAll);

clob.putString(1L, sAll);

ps = con.prepareStatement(sqlUpdate);

ps.setClob(1, clob);

ps.executeUpdate();

//         int writeClob;

//         while ( (writeClob = in.read()) != -1) {

//           out.write(writeClob);

//         }

countReplain++; //統計目前已經導入的大文本個數

con.commit();

con.setAutoCommit(true);

}

} catch (Exception e1) {

System.out.println("Lose file:" + path);

if (in != null)

in.close();

//if(out!=null)out.close();

//----

}

if (rs != null)

rs.close();

if (st != null)

st.close();

if (ps != null)

ps.close();

if (psSel != null)

psSel.close();

if (con != null)

con.close();

//----

}

System.out.println("共有文件" + countReplain);

} catch (Exception e) {

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值