public class Java1
{public Java1()
{Class.forName("com.mysql.jdbc.Driver").newInstance();}
public static void main(String args[])
{Java1 j1=new Java1();}
}
编译时显示加载驱动程序出错,错误如下:
Java1.java:5: unreported exception java.lang.ClassNotFoundException; must be caught or declared to be thrown
{Class.forName("com.mysql.jdbc.Driver").newInstance();}
^
Java1.java:5: unreported exception java.lang.InstantiationException; must be caught or declared to be thrown
{Class.forName("com.mysql.jdbc.Driver").newInstance();}
public class Java2
{
public static void main(String args[])
{try
{Class.forName("com.mysql.jdbc.Driver").newInstance();}
catch(Exception e)
{}
Connection conn;
conn=DriverManager.getConnection("jdbc:mysql://localhost/test?user=root");
}
}
编译时错误如下:
Java2.java:16: unreported exception java.sql.SQLException; must be caught or declared to be thrown
conn=DriverManager.getConnection("jdbc:mysql://localhost/test?user=root");
^
1 error