2 z1z9x85 Z1Z9X85 于 2014.10.21 13:00 提问

eclipse导入连接数据库需要的三个jar包后,还是连不上数据库

代码如下:
mport java.sql.*;
import java.util.Vector;
import javax.swing.*;
public class Test1 extends JFrame{

JTable jt=null;
JScrollPane jsp=null;
Vector rowData=null;
Vector columnName=null;
Connection cn=null;
PreparedStatement ps=null;
ResultSet rs=null;
public static void main(String[] args) {
    // TODO Auto-generated method stub
    Test1 t1=new Test1();
}
public Test1()
{
    columnName=new Vector();
    columnName.add("学生编号");
    columnName.add("学生名");
    columnName.add("性别");
    columnName.add("年龄");
    columnName.add("籍贯");
    columnName.add("所在系");

    rowData=new Vector();

    try {
        Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
        cn=DriverManager.getConnection(/*"jdbc:odbc:mytest"*/"jdbc:microsoft:sqlserver://127.0.0.1:1433;databaseName=test","sa","sa");
        ps=cn.prepareStatement("select * from stu");
        rs=ps.executeQuery();
        while(rs.next())
        {
            Vector hang=new Vector();
            String stuId=rs.getString(1);
            hang.add(stuId);
            String stuName=rs.getString(2);
            hang.add(stuName);
            String stuSex=rs.getString(3);
            hang.add(stuSex);
            int stuAge=rs.getInt(4);
            hang.add(stuAge);
            String stuJG=rs.getString(5);
            hang.add(stuJG);
            String stuDept=rs.getString(6);
            hang.add(stuDept);
            rowData.add(hang);
        }
    } catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
    }finally{
            try {
                if(rs!=null) rs.close();
                if(ps!=null) ps.close();
                if(cn!=null) cn.close();
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
    }
    jt=new JTable(rowData,columnName);
    jsp=new JScrollPane(jt);
    this.add(jsp);
    this.setLocation(400, 300);
    this.setSize(300,200);
    this.setDefaultCloseOperation(EXIT_ON_CLOSE);
    this.setVisible(true);

}

}
报错如下:
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 com.class69.Test1.(Test1.java:35)
at com.class69.Test1.main(Test1.java:20)

CSDN移动问答

请问:这是哪里出问题了?

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!