首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

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

2012-10-27 
java.sql.SQLException: The url cannot be null寻求帮助public class DBUtile {private static final Str

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); } 

热点排行