我在eclipse环境下写了一个与sqlserver2000连接的程序,但总是出现错误,
我在eclipse环境下写了一个与sqlserver2000连接的程序
但总是出现异常,请高手帮忙看一下吧
package initial;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class Database {
/**
* @param args
*/
public static void main(String[] args) {
String sql= "select * from student ";
try{
Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ").newInstance();
String url= "jdbc:microsoft://localhost:1433;DatabaseName=mydb ";
String user= "langmanbusi ";
String password= "889261 ";
Connection cnn=DriverManager.getConnection(url, user, password);
Statement st=cnn.createStatement();
ResultSet rs=st.executeQuery(sql);
while(rs.next())
{
ystem.out.println(rs.getString(1));
System.out.println(rs.getString(2));
System.out.println(rs.getString(3));
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
出现的异常是
java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at myds.Mydsn.main(Mydsn.java:17)
------解决方案--------------------你的sqlserver2000
要装一下。sqlserver SP4
------解决方案--------------------找不到类呗,把那三个jar放到classspath
------解决方案--------------------找不到这个驱动 com.microsoft.jdbc.sqlserver.SQLServerDriver
------解决方案--------------------你要先把那3个驱动包加载进去,然后你要是用微软的连接方式就下一个sp4补丁安装上,才可以正常连接!
------解决方案--------------------msbase.jar,msutil.jar,mssqlserver.jar