db.url=jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=Student_info
这是属性
package com.simon.db;
import java.sql.*;
import java.util.*;
public class DBConnect {
public DBConnect() {
}
public static Connection getConnection() {
ResourceBundle rb = ResourceBundle.getBundle("db");
try {
String driverName = rb.getString("db.driver");
Driver dirver = (Driver)Class.forName(driverName).newInstance(); 这里是第16行
String url = rb.getString("db.url");
Connection con = DriverManager.getConnection(url);
return con;
} catch(ClassNotFoundException cnfExc) {
System.out.println(cnfExc.getMessage());
cnfExc.printStackTrace();
} catch(SQLException sqlExc) {
System.out.println(sqlExc.getMessage());
sqlExc.printStackTrace();
} catch(IllegalAccessException e) {
System.out.println(e.getMessage());
e.printStackTrace();
} catch(Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
System.out.print("afda");
return null;
}
public static void main(String[] args) throws Throwable{
Connection con = getConnection(); 这是41行
//Statement stmt = con.createStatement();
}
}
com.microsoft.jdbc.sqlserver.SQLServerDriver
afdajava.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:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:164)
at com.simon.db.DBConnect.getConnection(DBConnect.java:16)
at com.simon.db.DBConnect.main(DBConnect.java:41)