how to resolve Got minus one from a read call in oracle 11g jdbc 7/14 jdk 1.7?

前端 未结 4 1521
旧巷少年郎
旧巷少年郎 2021-01-20 08:44

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         


        
4条回答
  •  太阳男子
    2021-01-20 09:30

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

提交回复
热议问题