一个连接数据库的小问题
package yyy;
/**
* <p>Title: 连接数据库</p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author
* @version 1.0
*/
import java.sql.*;
public class LianJie
{
public LianJie()
{
}
public static void main(String args[])
{
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
try
{
Class.forName("com.microsoft.jdbc.Sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs";
String loginName="sa";
String password="sa";
conn=DriverManager.getConnection(url,loginName,password);
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="Select * from student";
rs=stmt.executeQuery(sql);
while(rs.next())
{
System.out.print(rs.getString(1));
System.out.print(""+rs.getString(2));
System.out.println(""+rs.getString(3));
}
}
catch(SQLException e)
{
System.out.println(e.toString());
}
finally
{
stmt.close();
rs.close();
}
}
}
错误就是:
--------------------Configuration: yyy - JDK version 1.3.1 <Default>--------------------
d:\Program Files\Xinox Software\JCreator Pro\MyProjects\yyy\Yyy.java:28: unreported exception java.lang.ClassNotFoundException; must be caught or declared to be thrown
Class.forName("com.microsoft.jdbc.Sqlserver.SQLServerDriver").newInstance();
^
d:\Program Files\Xinox Software\JCreator Pro\MyProjects\yyy\Yyy.java:28: unreported exception java.lang.InstantiationException; must be caught or declared to be thrown
Class.forName("com.microsoft.jdbc.Sqlserver.SQLServerDriver").newInstance();
^
d:\Program Files\Xinox Software\JCreator Pro\MyProjects\yyy\Yyy.java:52: unreported exception java.sql.SQLException; must be caught or declared to be thrown
stmt.close();
^
d:\Program Files\Xinox Software\JCreator Pro\MyProjects\yyy\Yyy.java:53: unreported exception java.sql.SQLException; must be caught or declared to be thrown
rs.close();
^
4 errors
Process completed.
菜鸟想请教大虾,这是为什么?
问题点数:20、回复次数:4Top




