我建了一个属性文件database.properties用来提供jdbc属性和想从publishers.sql 文件中读取SQL命令 并在程序中执行但是却出现错误:
代码如下:import java.io.*;
import java.sql.*;
import java.util.*;public class TestDB2 {    public static void main(String[] args) {
     try {
     Scanner in;
     if(args.length==0)
     in=new Scanner(System.in);
     else
     in=new Scanner(new File(args[0]));
     Connection conn=getConnection();
     try {
     Statement stat=conn.createStatement();
     while(true) {
     if(args.length==0) System.out.println("Enter command or EXIT to exit:");
     if(!in.hasNextLine()) return;
    
     String line=in.nextLine();
     if(line.equalsIgnoreCase("EXIT")) return;
     try {
     boolean hasResultSet=stat.execute(line);
     if(hasResultSet)
     showResultSet(stat);
     }
     catch(SQLException e) {
     while(e!=null) {
     e.printStackTrace();
     e=e.getNextException();
     }
     }
     }
     }
     finally {
     conn.close();
     }
     }
     catch(SQLException e) {
     while(e!=null) {
     e.printStackTrace();
     e=e.getNextException();
     }
     }
     catch(IOException e) {
     e.printStackTrace();
     }
    
    }
    
     public static Connection getConnection() throws SQLException ,IOException {
      Connection conn=null;
    
     Properties props=new Properties();
     FileInputStream in= new FileInputStream("database.properties");
     props.load(in);
     in.close();
    
     String drivers=props.getProperty("jdbc.drivers");
     if(drivers!=null) System.setProperty("jdbc.drivers",drivers);
    
     String url=props.getProperty("jdbc.url");
     String username=props.getProperty("jdbc.username");
     String password=props.getProperty("jdbc.password");     return DriverManager.getConnection(url,username,password);
    }
    public static void showResultSet(Statement stat) throws SQLException {
     ResultSet result=stat.getResultSet();
     ResultSetMetaData metadata=result.getMetaData();
     int column=metadata.getColumnCount();
    
     for(int i=1;i<=column;i++) {
     if(i>1) System.out.print(",");
     System.out.print(metadata.getColumnLabel(i));
     }
     System.out.println();
     while(result.next()) {
     for(int i=1;i<=column;i++) {
     if(i>1) System.out.print(",");
     System.out.print(result.getString(1));
     }
     System.out.println();
     }
     result.close();
    }
    
}
------------------------------------------------------------------------------------------------------------------------------------------------------
Error Messages:D:\wallpaper\COREJAVA>java TestDB2 Publishers.sql
java.sql.SQLException: General error message from server: "No tables used"
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2001)
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1168)
        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1279)
        at com.mysql.jdbc.MysqlIO.sqlQuery(MysqlIO.java:1225)
        at com.mysql.jdbc.Connection.execSQL(Connection.java:2278)
        at com.mysql.jdbc.Connection.execSQL(Connection.java:2225)
        at com.mysql.jdbc.Statement.execute(Statement.java:906)
        at TestDB2.main(TestDB2.java:32)