当前位置: 代码迷 >> Java Web开发 >> java.sql.SQLException: The url cannot be null 谋求帮助
  详细解决方案

java.sql.SQLException: The url cannot be null 谋求帮助

热度:10013   发布时间:2013-02-25 21:09:41.0
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); }
  相关解决方案