java连接SQL Sever 2008的问题~求大神帮忙看看.弄了我两天都弄不明白...积分没了
程序代码:
package com.test2; import java.sql.*; public class Deom3 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub PreparedStatement ps=null; Connection ct=null; ResultSet rs=null; try { //加载驱动 Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); //得到链接 ct=DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1443;databaseName=sqdb1","sa","langhaopan5672"); ps=ct.prepareStatement("select * from dept"); rs=ps.executeQuery( ); while(rs.next()){ System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3)); } } catch (Exception e) { // TODO Auto-generated catch block 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(); } } } }运行出现下面的异常,我的是SQL Server 2008 r2 .电脑系统win7 64位
sqljdbc4.jar也加到项目的Java Build Path中的Libraries上了。求大神指点~~(我用jdbc-odbc的方法也是有问题)
java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver
at (URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at (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.test2.Deom3.main(Deom3.java:18)