各位大虾,我写的程序如下:
import java.io.*;
import javax.sql.*;
import java.sql.*;
import javax.naming.*;
import java.util.*;
import java.lang.*;
        
public class Check_word {
        
    public static void main(String[] args) {
        char Char8xx[] = new char [881];
        char WordLine[] = new char[8192];
        //char Word[] = new char[10];
        StringBuffer CharNoString = new StringBuffer();
        StringBuffer Word = new StringBuffer();
        String cmd = new String();
        File InputCharFile = new File("char8xx.txt");
        File InputWordFile = new File("py81.txt");
        int i, j, k, l, WordLen = 0;
        int NumberOfRead = -1;
        Statement stm = null;
        Connection con = null;
        FileReader InWord = null;
        FileReader InChar  = null;
        
        //connect database
        final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
        final String DATABASE_URL = "jdbc:mysql://localhost/wordbase";
       try{
           
           Class.forName(JDBC_DRIVER);
           con = DriverManager.getConnection(DATABASE_URL, "root", "root");
           stm = con.createStatement();
           
       }
       catch(ClassNotFoundException e){
           System.out.println("class not found");
           System.exit(1);
       }
       catch(SQLException e){
           System.out.println("SQL exception in connection");
           System.exit(1);
       }
                      
         //read the 8xx char to array char8xx
        try {
            InChar = new FileReader(InputCharFile);
            
            try{
                InChar.read(Char8xx);
                
            }
            catch(Exception e){
                System.out.println("error during read char file");
                System.exit(1);
            }
        }
        catch(FileNotFoundException e){
            System.out.println("Char File Not Found");
            System.exit(1);
        }
        
        //init Inword
        try{
             InWord = new FileReader(InputWordFile);
             
        }
        catch(FileNotFoundException e){
            System.out.println("Word file not found");
            System.exit(1);
        }
        
        //read word line by line to buffer,check whether the word only includes the 8xx char
        //if it is, write them to word database
        do{
               //read in wordfile line by line
               try{
                    NumberOfRead = InWord.read(WordLine);
                }
               catch(Exception e){
                    System.out.println("error during read char file");
                    System.exit(1);
                }
               
               //get a word from WordLine and check
               for(i=0; i<8192; i++){
                   if (WordLine[i] != '\n'){
                      Word.append(WordLine[i]); 
                   }
                   else{
                      System.out.println(Word);
                      WordLen = Word.length();
                      CharNoString.append('$');
                      for(j=0; j<(WordLen); j++){
                          for(k=0; k<881; k++){
                             
                              //if found word.charat(j) in Char8xx,break
                              
                              if(Word.charAt(j) == Char8xx[k]){
                                   System.out.println(Char8xx[k]);
                                   CharNoString.append((char)k + '$');
                                   break;
                              }
                          }
                          
                          //if the k iteration is ended because of offset, it means Word.charat(j) not found, end the j iteration
                          if(k == 881 ) {
                              Word.delete(0,WordLen);
                              CharNoString.delete(0, CharNoString.length());
                              break;
                          }
                      }
                      //if j iteration is ended because of offset, it means the whole word is found, store it to database
                      
                      if(j == (WordLen - 1)){
                         
                         cmd = "INSERT INTO words (word, NumberOfCount, CharNoString) VALUES(" + Word + "," + (char)j +"," + CharNoString + ")";
                          Word.delete(0,WordLen);
                         CharNoString.delete(0, CharNoString.length());
                        
                         try{
                             stm.execute(cmd);
                         }
                         catch(SQLException e){
                             System.out.println("error during insert");
                             System.exit(1);
                         }
                      }
                   }
               }
             } while(NumberOfRead == 8192);
                
        
    }
   
}这个程序的目的是把char8xx.txt(是一个字库)文件读进数组,然后在把py81.txt(是个词库,每个词都以\n结尾)文件的内容一每次8192个读进,然后检查其中的哪一个词是完全由char8xx字库里的字构成的,如果找到一个,就将其存如数据库。程序执行的时候,数据库连接没有问题,因为connection部分没有报错,但是在写入数据库时(就是程序的倒数第五个语句:stm.execute(cmd)),catch到SQLException.请问是什么问题啊?