Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Invalid column index

simramkumarAug 4 2011 — edited Aug 4 2011
SELECT SEQUENCE_NAME FROM USER_SEQUENCES

select dbms_metadata.get_ddl('SEQUENCE','CUSTOMERS_SEQ','JAZZDBUSER') from dual

While Executing the above query through java i am getting the below error. The same is working through sqlplus. Can anybody help me out to solve the issue.

java.sql.SQLException: Invalid column index
at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70)
at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:131)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:197)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:261)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:269)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:490)
at oracle.jdbc.driver.OracleResultSetImpl.getString(OracleResultSetImpl.java:860)
at Test.createOracleSequence(Test.java:49)
at Test.main(Test.java:20)


Java Code:


import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

public class Test {
private static Connection conn;
private static int sequenceCount;
private static String dbUser = "JAZZDBUSER";

/**
* @param args
*/
public static void main(String[] args) {
try {
conn = getOracleConnection("jdbc:oracle:thin:@localhost:1521:ORCL", "JAZZDBUSER", "JAZZDBUSER");
createOracleSequence();
} catch (Exception e) {
e.printStackTrace();
}
}

public static Connection getOracleConnection(String dbURL, String userName, String passWord) throws ClassNotFoundException, SQLException, Exception {
String driver = "oracle.jdbc.driver.OracleDriver";
Class.forName(driver); // load Oracle driver
Connection conn = DriverManager.getConnection(dbURL, userName, passWord);
return conn;
}

private static void createOracleSequence() throws SQLException, IOException {
ArrayList<String> sequenceStructure = new ArrayList<String>();
String sql = "SELECT SEQUENCE_NAME FROM USER_SEQUENCES";
System.out.println(sql);
Statement stt = conn.createStatement();
ResultSet rs = stt.executeQuery(sql);
StringBuffer tableQuery = new StringBuffer();
Statement tableStt = conn.createStatement();
ResultSet rsTable = null;
while (rs.next()) {
tableQuery = new StringBuffer();
tableQuery.append("select dbms_metadata.get_ddl('SEQUENCE','" + rs.getString("SEQUENCE_NAME") + "','" + dbUser.toUpperCase() + "') from dual");
System.out.println(tableQuery.toString());
rsTable = tableStt.executeQuery(tableQuery.toString());
while (rsTable.next()) {
sequenceCount++;
sequenceStructure.add(rsTable.getString(3));
}
}
if (rs != null) {
rs.close();
}
if (rsTable != null) {
rsTable.close();
}
stt.close();
tableStt.close();
}
}

Edited by: user10098994 on Aug 4, 2011 12:20 AM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 1 2011
Added on Aug 4 2011
1 comment
680 views