调试总是出错,请名师指点!!急在线等待(30分)

  • 主题发起人 主题发起人 yj3385
  • 开始时间 开始时间
Y

yj3385

Unregistered / Unconfirmed
GUEST, unregistred user!
代码:
import java.sql.*;
class first_ext
{
public static void main(String[] args)
{
String queryString = "select * from Customers";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection myConn = DriverManager.getConnection("jdbc:odbc:first_exp","sa","45454");
Statement myStmt = myConn.createStatement();
ResultSet myResults = myStmt.executeQuery(queryString);
System.out.println("Hello World!");
}
}
出错信息---------------------------------------
D:/aa/java/exp/first_exp.java:10: unreported exception java.lang.ClassNotFoundException;
must be caught or declared to be thrown
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
^
D:/aa/java/exp/first_exp.java:11: unreported exception java.sql.SQLException;
must be caught or declared to be thrown
Connection myConn = DriverManager.getConnection("jdbc:odbc:first_exp","sa","45454");
 
要求你捕捉异常:如public boolean disconnect() throws SQLException {
.....
try {}
catch(Exception e)
{
}
 
后退
顶部