新手求助!Eclipse中连接sqlserver2000数据库,用maven管理包,出现如下错误
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.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at Method.getAllData(Method.java:19)
at Method.main(Method.java:77)----------------------------------------------
连接数据库用的是jtds-1.2.[color=#FF0000][/color]-----------------------------------------------
import java.sql.DriverManager;
import java.sql.ResultSet;
import
java.sql.SQLException;
import java.sql.Statement;
import java.util.Vector;
public class Method
{
public Vector<Message> getAllData()
{
Vector<Message> mes = new Vector<Message>();
Connection conn = null;
Statement st = null;
ResultSet rs = null;
//1、加载驱动
try
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
//2、创建连接对象
conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs","sa","123");
//3、创建语句执行器
st = conn.createStatement();
String sql = "select id, name, sex from message";
//4、执行数据库操作
rs = st.executeQuery(sql);
while(rs.next())
{
Message m = new Message();
m.setId(rs.getInt(1));
m.setName(rs.getString(2));
m.setSex(rs.getString(3));
mes.add(m);
}
}
catch (
ClassNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (
SQLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
if(st != null)
{
try
{
st.close();
}
catch (SQLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(conn != null)
{
try
{
conn.close();
}
catch (SQLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return mes;
}
public static void main(String[] args)
{
System.out.println(new Method().getAllData());
}
}
----------------------------------------------------
能帮一下看看什么错误吗?实在是看不出来
------解决方案--------------------
java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver
Jar包引入了没有?