JDBC - 数据库失败

时间:2012-06-19 00:39:52

标签: google-app-engine jdbc

我有以下方法遇到某种类型的数据库故障。没有错误写入我的控制台,所以我很困惑。我正在使用JDBC和Google AppEngine。有人可以帮帮我吗?感谢。

public List<Bulletin> getApprovedBulletins() {
    List<Bulletin> bulletins = new ArrayList<Bulletin>();

    try {
        Connection connection = getConnection();
        Statement statement = connection.createStatement();
        statement.executeQuery("select * from bulletins where approved = true");
        ResultSet resultSet = statement.getResultSet();

        while (resultSet.next()) {
            Bulletin bulletin = new Bulletin();
            bulletin.setId(resultSet.getInt("id"));
            bulletin.setDate(resultSet.getDate("bulletin_date"));
            bulletin.setName(resultSet.getString("name"));
            bulletin.setSubject(resultSet.getString("subject"));
            bulletin.setNote(resultSet.getString("bulletin"));

            bulletins.add(bulletin);
        }

        resultSet.close();
        connection.close();
        return bulletins;
        }
        catch (Exception e) {
            System.out.println(e.toString());
        }

    return null;
}

private Connection getConnection() {
    Connection conn = null;
    String url = "jdbc:mysql://localhost:3306/cpc";
    String driver = "com.mysql.jdbc.Driver";
    String userName = "root";
    String password = "password";
    try {
        Class.forName(driver).newInstance();
        conn = DriverManager.getConnection(url, userName, password);
    } catch (Exception e) {
        return null;
    }

    return conn;
}

2 个答案:

答案 0 :(得分:0)

如果您正在使用eclipse,请检查标记选项卡是否有错误。请注意,驱动程序也必须位于应用程序服务器文件夹中才能工作。不知道为什么你在控制台中没有收到任何错误......

答案 1 :(得分:0)

问题解决了。我找到了一个向我的控制台打印消息的地方,结果我需要将以下内容添加到appengine-web.xml中,我已经完成了。

<sessions-enabled>true</sessions-enabled>
相关问题