I did this JDBC code for fetching some data from the database Oracle 10g using Play Framework 1.2.5:
Connection conn = DB.getConnection();
PreparedStatement stmt = null;
System.out.println(conn);
try {
stmt = conn.prepareStatement("select dept_id from emp where emp_id = 11");
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
System.out.println("Dept Id: " + rs.getInt("dept_id"));
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
This approach is working but I am having a confusion:
If I comment the entire block of code and run the application then I can see the message in the console stating the connection is made to the DB. Hence :
1) Is the above block of code the right approach to fetch the data from Oracle DB or something better than this is present?
2) Is it like for the entire application lifetime, the connection with tht DB will persist?
I am a newbie in this, hence struggling 🙁
Please let me know hoe to proceed with this.
Regards
You need to read the play JPA documentation: http://www.playframework.org/documentation/1.2.5/jpa#finding
Your queries should look like this:
And if you need to do a full query, you can add the JPA code in find: