oracle数据库的名称为:mydata,用户名:system,密码:abcde,我想与数据库建立连接并输出表client中的前两列,请大家指教错在那里?
import java.sql.*; 
public class Oracle{
  public static void main(String[] args){
Connection conn = DriverManager.getConnection ("jdbc:odbc:mydata", "system", "abcde");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM client");
while(rs.next()){
System.out.println("您的第一个字段内容为:"+rs.getString(1));
System.out.println("您的第二个字段内容为:"+rs.getString(2));
}
System.out.println("数据库操作成功,恭喜你");
rs.close();   
stmt.close();   
conn.close();    }
}

解决方案 »

  1.   

    部分java编译器会强制你用异常处理,否则会出错.
    加多
      try...就可以了.
      

  2.   

    几乎所有的数据库操作会产生异常的,需要加上try、catch处理。
    另外,这是十分简单的JAVA程序了,楼主需要多多看书啊。
    有JAVA的问题,多到JAVA版问吧,那里的人对JAVA了解得比较多。
      

  3.   

    错误信息如下:Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
    Unhandled exception type SQLException
    Unhandled exception type SQLException
    Unhandled exception type SQLException
    Unhandled exception type SQLException
    Unhandled exception type SQLException
    Unhandled exception type SQLException
    Unhandled exception type SQLException
    Unhandled exception type SQLException
    Unhandled exception type SQLException at Oracle.main(Oracle.java:4)
      

  4.   

    没有处理SQLExceptiontry{
    ........}
    catch(SQLException sqle)
    System.out.print(sqle);
    }