日期:2014-05-17  浏览次数:21162 次

java.sql.SQLException: The url cannot be null 寻求帮助
public class DBUtile {

private static final String DRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
private static final String URL = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=bigTang";
private static final String USER = "sa";
private static final String PASSWORD = "123123";
private static Properties pro = null;

static {
pro = new Properties();
try {
pro.load(DBUtile.class.getClassLoader().getResourceAsStream(
"com/struts2/jackiy/db/jdbc.properties"));
Class.forName(DBUtile.getString(DRIVER));
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

public static Connection getConnection() {

try {
System.out.println("aq");
return DriverManager.getConnection(DBUtile.getString(URL), DBUtile
.getString(USER), DBUtile.getString(PASSWORD));
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}

public static void closeConnection(Connection conn, Statement stmt,
ResultSet rs) {

try {
if (conn != null) {
conn.close();
}
if(stmt!=null){
stmt.close();
}
if(rs!=null){
stmt.close();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

public static String getString(String key) {
return pro.getProperty(key);
}

public static void main(String[] args) {
System.out.println(DBUtile.getConnection());
}
}



----------------------

我 使用 conn = DBUtile.getConnection();

就报错 conn = DBUtile.getConnection();

请 赐教 咋回事

------解决方案--------------------
问题在于
Java code

DBUtile.getString(URL);
public static String getString(String key) {
 return pro.getProperty(key);
 }