问题描述
- sql 2005跟哪些版本的eclipse能连接。。
-
还有能不能帮忙告诉我,有什么代码能看数据库是否连接。。谢谢顺便帮我看下下面的代码哪里错了
代码如下:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;public class DBUtils {
private static final String className = null;private DBUtils(){} private static DBUtils instance = null; public synchronized static DBUtils getInstance(){ if(instance == null) { instance = new DBUtils(); } return instance; } String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";// 数据库驱动字符串 String url = "jdbc:sqlserver://127.0.0.1:1433;DatabaseName=MyCRM";// 连接URL String user = "sa"; // 数据库用户名 String password = "juemi2135"; // 用户密码 public Connection getConnection() throws SQLException { Connection conn=null; try { Class.forName(className); conn = DriverManager.getConnection(url, user, password); } catch (ClassNotFoundException e) { e.printStackTrace(); } return conn; } public static void main(String[] args) throws SQLException { long begin = System.currentTimeMillis(); for(int i=0;i<1000;i++){ Connection conn = DBUtils.getInstance().getConnection(); conn.close(); } long end=System.currentTimeMillis(); System.out.println(end-begin); }
}
错误如下:
Exception in thread "main" java.lang.NullPointerException
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at DBUtils.getConnection(DBUtils.java:29)
at DBUtils.main(DBUtils.java:40)
时间: 2024-10-06 01:13:59