请czb(草中宝)回答一下,还是连接数据库的问题
import java.sql.*;
public class ListClasses
{ public static void main (String[] args)
{ int i, NoOfColumns;
String ClassName,ClassLocation, ClassSchedule;
//Initialize and load the JDBC-ODBC driver.
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
//Make the connection object.
Connection Ex1Con = DriverManager.getConnection("jdbc:odbc:StudentDB;uid=admin;pw=sa");
//Create a simple Statement object.
Statement Ex1Stmt = Ex1Con.createStatement();
//Make a SQL string, pass it to the DBMS, and execute the SQL statement.
ResultSet Ex1rs = Ex1Stmt.executeQuery( "SELECT ClassName, Location,DaysAndTimes FROM Classes");
//Process each row until there are no more rows.
// And display the results on the console.
System.out.println("Class Location Schedule");
while (Ex1rs.next())
{
// Get the column values into Java variables
ClassName = Ex1rs.getString(1);
ClassLocation = Ex1rs.getString(2);
ClassSchedule = Ex1rs.getString(3);
System.out.println(ClassName + ClassLocation + ClassSchedule);
}
}
}
我用的是JDK1.2,CLASSPATH和PATH都已设置好,但有两个错误,内容为:
F:\Study\Java\JDBC\ListClasses.java:9: Exception java.lang.ClassNotFoundException must be caught, or it must be declared in the throws clause of this method.
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
^
F:\Study\Java\JDBC\ListClasses.java:12: Exception java.sql.SQLException must be caught, or it must be declared in the throws clause of this method.
Connection Ex1Con = DriverManager.getConnection("jdbc:odbc:StudentDB;uid=admin;pw=sa");
^
2 errors
Process completed with exit code 1
请多多指教,谢谢.