我在使用 mysql 后尝试使用 oracle,并且有一个关于从 db 表中获取信息的问题。这就是我所拥有的。
PreparedStatement statement = null;
ResultSet resultSet = null;
List<News> newsList = new ArrayList<News>();
try {
statement = connection.
prepareStatement(NewsSQLQueryContainer.GET_NEWS_LIST);
resultSet = statement.executeQuery();
while (resultSet.next()) {
News news = new News();
news.setIdNews(resultSet.getInt("idnews"));
news.setInfo(resultSet.getString("info"));
news.setNewsDate(resultSet.getDate("newsdate"));
news.setNewsHeader(resultSet.getString("newsheader"));
newsList.add(news);
}
}
并且连接是从我自己的池中接收的,它以这种方式初始化:
public static void init() throws DAOException{
if(instatance == null){
ResourceBundle rb = ResourceBundle.getBundle(PROPERTIES_FILENAME);
String driver = rb.getString("DATABASE_DRIVER_NAME");
String url = rb.getString("DATABASE_URL");
String user = rb.getString("DATABASE_USER");
String password = rb.getString("DATABASE_PASSWORD");
String poolSizeStr = rb.getString("DATABASE_POOLSIZE");
int poolSize = (poolSizeStr != null) ?
Integer.parseInt(poolSizeStr) : DEFAULT_POOL_SIZE;
log.info("Trying to create pool of connections...");
instatance = new ConnectionPool(driver,url,user,password,poolSize);
log.info("Connection pool initialized");
}
从此属性文件中:
DATABASE_DRIVER_NAME=oracle.jdbc.driver.OracleDriver
DATABASE_URL=jdbc:oracle:thin:@localhost:1521:ORCL
DATABASE_USER=root
DATABASE_PASSWORD=root
DATABASE_POOLSIZE=40
几乎相同的代码与 mysql 一起工作,现在不工作(没有结果集)。从 oracle 获取信息有什么特殊方法吗?
修复它:只是忘记了这个用户对这个数据库没有这样的权限