向数据库中输入数据失败 ,大家指教!

zhangxia05311466 2007-12-22 09:27:41
private static String chapterValue;
private static Hashtable hashtable=new Hashtable();
private static String titleValue;
private static String sectionValue;
private static String gazettenumberValue;
private static String headingValue;
private static String versiondateValue;
// private static InputStream contentValue;
private static String docnameValue;
private static String cfilenameValue;

public static void ReadDataToDB(String dir,String corpus)
{
File pathE = new File(dir);
File list[] ;
list=pathE.listFiles() ;
String SQLStr=new String() ;
//String fn="";
String str;

byte st[]=null;
InputStream fis=null;
PreparedStatement pstmt=null;
StringBuffer data= new StringBuffer();
Connection conn =m_Conn.conn;
try{
for(int i = 0; i < list.length; i++)

// for(int i = 0; i < 1; i++)
{
try{
fis = new FileInputStream(list[i]);

st=new byte[(int)list[i].length()];//listE[i]是文件的长度
int b=fis.read(st,0,fis.available());//把输出流中的数据读到字节数组st中
str=new String(st,0,b);
data = new StringBuffer(str);
}catch (IOException e)
{System.out.println("opening file has errors");
}
try {
if(corpus.compareTo("e")==0||
corpus.compareTo("e-sc")==0 ||
corpus.compareTo("e-c")==0)

{
processFile_e(data, list[i].getName());
}
else if (corpus.compareTo("GB")==0||corpus.compareTo("Big5")==0 )
{

processFile_sc(data, list[i].getName());
}
} catch (IOException e) {
System.out.println("processing file has errors");
}


SQLStr = "Insert Into GBCorpus (Chapter,Title,Section,GazetteNumber,Heading,VersionDate,Content,FileName,EfileName,ID) values(?,?,?,?,?,?,?,?,?,?)";
pstmt = conn.prepareStatement(SQLStr);
pstmt.setString(1,chapterValue);
pstmt.setString(2,titleValue);
//pstmt.setString(3,sectionValue);
pstmt.setString(4,gazettenumberValue);
pstmt.setString(5,headingValue);
pstmt.setString(6,versiondateValue);
pstmt.setBytes(7,st);
pstmt.setString(8,docnameValue);
pstmt.setString(9,cfilenameValue);
pstmt.setInt(10,i);//1-30000
//pstmt.setInt(10,i+30000);//30000

pstmt.executeUpdate();

} catch (SQLException sqle){System.out.println("write to database having wrong");}
System.out .println(i) ;

}

try{ fis.close();}catch(IOException e)
{System.out.println(e);
}
conn.commit();
conn.close();
} catch (SQLException sqle){System.out.println(sqle.getMessage());}
}


以上是部分代码,以前可以顺利运行的,重装服务器后,出现以下问题:
运行程序,连接上数据库,但是输出:write to database having wrong, 数据不能写入数据库,向大家请教什么原因?
...全文
74 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
rouqu 2007-12-22
  • 打赏
  • 举报
回复
做程序SQL语句调试的时候 推荐把SQL Profiler打开
rouqu 2007-12-22
  • 打赏
  • 举报
回复
呵呵 看到这句错误"write to database having wrong" 还在想 哪个程序报错这么不专业呢..

34,593

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧