I am using netbeans and jdk 7 updt 9 with 1.7 and following is my code.
public class jd {
public static void main(String[] args) throws ClassNotFoundExcep
Try this code:
OracleDataSource ods = new OracleDataSource();
ods.setUser(DB_USER));
ods.setPassword(DB_PASSWORD);
ods.setURL(jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(HOST=myhost)(PORT=1521)(PROTOCOL=tcp))(CONNECT_DATA=(SERVICE_NAME=myorcldbservicename))));
// New AutoClosable syntax applicable to connection. This syntax will
// close the connection automatically
try (OracleConnection connection = (OracleConnection) (ods.getConnection())) {
// Statement and ResultSet are AutoClosable by this syntax
try (Statement statement = connection.createStatement()) {
try (ResultSet resultSet = statement.executeQuery("select sysdate from dual")) {
while (resultSet.next())
System.out.print("Today's Date is: " + resultSet.getString(1));
}
}
}