日期:2014-05-20 浏览次数:20849 次
package com.text; import javax.swing.*; import java.awt.*; import java.util.*; import java.sql.*; import java.awt.event.*; public class text1 extends JFrame{ Vector rowDate,columnNames; JTable jt=null; JScrollPane jsp=null; //定义数据库需要的 PreparedStatement ps=null; Connection ct=null; ResultSet rs=null; public static void main(String[] args) { text1 tt=new text1(); } public text1() { columnNames=new Vector(); columnNames.add("学号"); columnNames.add("姓名"); columnNames.add("性别"); columnNames.add("年龄"); columnNames.add("籍贯"); columnNames.add("门派"); rowDate=new Vector(); System.out.println("ok1"); try { //加载驱动 Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); ct=DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1433;databaseName=stuText"); ps=ct.prepareStatement("select * from stu"); rs=ps.executeQuery(); System.out.println("ok2"); while(rs.next()) { Vector hang=new Vector(); hang.add(rs.getString(1)); hang.add(rs.getString(2)); hang.add(rs.getString(3)); hang.add(rs.getInt(4)); hang.add(rs.getString(5)); hang.add(rs.getString(6)); rowDate.add(hang); } } catch (Exception e) { // TODO: handle exception e.printStackTrace(); }finally { try { if(rs!=null) { rs.close(); } if(ps!=null) ps.close(); if(ct!=null) ct.close(); } catch (Exception e2) { // TODO: handle exception e2.printStackTrace(); } } System.out.println("ok3"); jt=new JTable(rowDate,columnNames); jsp=new JScrollPane(jt); this.add(jsp); this.setSize(400, 300); this.setVisible(true); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }
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.text.text1.<init>(text1.java:35) at com.text.text1.main(text1.java:17)