简体   繁体   中英

How to get info from oracle database to java bean?

I'm trying to use oracle after using mysql and have a question about getting info from db tables. Here what I have.

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

and connection is received from my own pool, which initialize this way:

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

from this properties file:

DATABASE_DRIVER_NAME=oracle.jdbc.driver.OracleDriver
DATABASE_URL=jdbc:oracle:thin:@localhost:1521:ORCL
DATABASE_USER=root
DATABASE_PASSWORD=root
DATABASE_POOLSIZE=40

almost the same code worked with mysql and don't work now(gets nothing to result set). Is there any special approach with getting info from oracle?

Fixed it: just forgot that this user don't have such rights with this db

I don't think the problem you are having is to do with any difference between getting info from Oracle tables compared with MySQL tables. There doesn't look to be anything wrong with the way you are retrieving the result set (although it would be interesting to see the query contained in NewsSQLQueryContainer.GET_NEWS_LIST). Sorry for the obvious question - does your table contain any data?!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM