向数据库中输入数据失败 ,大家指教!
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, 数据不能写入数据库,向大家请教什么原因?