代码如下:
import java.sql.*;
 
public class JDBCExample {
 public static void main(String[] args) {
  try{
   Class.forName("oracle.jdbc.driver.OracleDriver");
   String url = "jdbc:oracle:thin:@127.0.0.1:1521:lwborclsid";
   Connection conn = DriverManager.getConnection(url, "scott", "tiger");
   Statement stmt = conn.createStatement();
   ResultSet rs = stmt.executeQuery("select * from dept");
   while(rs.next()) {
    System.out.print("DeptNo:" + rs.getInt(1));
    System.out.print("/tDeptName:" + rs.getString(2));
    System.out.println("/tLOC:" + rs.getString(3));
   }
   rs.close();
   stmt.close();
   conn.close();
  }catch(ClassNotFoundException e){
   System.out.println("找不到指定的驱动程序类");
  }catch(SQLException e){
   e.printStackTrace();
  }
 }
}问题提示如下:
java.lang.ArrayIndexOutOfBoundsException: 0
at oracle.jdbc.driver.OracleSql.main(OracleSql.java:1661)

解决方案 »

  1.   

    java.lang.ArrayIndexOutOfBoundsException: 0
    是不是你的结果集 只有2列数据?
      

  2.   

    ArrayIndexOutOfBoundsException数组索引越界异常LZ请看:
      System.out.print("DeptNo:" + rs.getInt(1));
      System.out.print("/tDeptName:" + rs.getString(2));
      System.out.println("/tLOC:" + rs.getString(3));应该是:
    rs.getInt(0),rs.getString(1),rs.getString(2);
      

  3.   

    查一下异常轨迹,看下是哪一行出现的ArrayIndexOutOfBoundsException异常.
    楼主应该要学会自己去分析问题,这种问题应该很好找的.
      

  4.   

    到数据库执行你的sql 看看实际的数据到底是多少 是不是数组越界了