日期:2014-05-18  浏览次数:20528 次

server2005大家帮我看看啊,错哪了啊?
//从数据库中取出元数
package com.test1;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Vector;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import java.sql.*;
public class Test2 extends JFrame {
//rowData表示行数,columnNames表示列数
Vector rowData,columnNames;
JTable jt=null;
JScrollPane jsp=null;
//定义连接数据库的足迹
PreparedStatement ps=null;
Connection ct=null;
ResultSet rs=null;
public static void main(String[] args) {
// TODO Auto-generated method stub
Test2 test2=new Test2();
}
public Test2(){
columnNames=new Vector();
//设置列名
columnNames.add("学号");
columnNames.add("姓名");
columnNames.add("性别");
columnNames.add("年龄");
columnNames.add("籍贯");
columnNames.add("系别");

rowData=new Vector();
try{
//加载驱动
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
ct=DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1443;databaseName=学生库","sa","");
ps=ct.prepareStatement("select * from stu");
rs=ps.executeQuery();

while(rs.next()){
//rowdata 可以存放多行
Vector hang=new Vector();
hang.add(rs.getString(1));
hang.add(rs.getString(2));
hang.add(rs.getString(3));
hang.add(rs.getString(4));
hang.add(rs.getString(5));
hang.add(rs.getString(6));
rowData.add(hang);
}
} catch(Exception e){
e.printStackTrace();
}finally{
//关闭
try{
if(rs!=null) rs.close();
if(ps!=null) ps.close();
if(ct!=null) ct.close();
}catch(Exception e){
e.printStackTrace();
}

}
//rowdata 可以存放多行

//初始化JTable
jt=new JTable(rowData,columnNames);
//初始化化Jsp JScrollPane
jsp=new JScrollPane(jt);
//吧jsp放入到jframe
this.add(jsp);
this.setSize(400,300);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);

}
}






报错提示:

java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at com.test1.Test2.<init>(Test2.java:38)
at com.test1.Test2.main(Test2.java:23)


------解决方案--------------------
jdbc连接不上
jdbc驱动装了没?