2

In sql developer if we type wrong query, e.g. delete from notable

it will show us exact line number and column

Error starting at line : 1 in command -
delete from notable
Error at Command Line : 1 Column : 13
Error report -
SQL Error: ORA-00942: table or view does not exist
00942. 00000 -  "table or view does not exist"
*Cause:    
*Action:

but if I do it in java code I got only

java.sql.SQLException: ORA-00942: table or view does not exist

at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112) ~[ojdbc14-10.2.0.3.0.jar:Oracle JDBC Driver version - "10.2.0.3.0"]
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331) ~[ojdbc14-10.2.0.3.0.jar:Oracle JDBC Driver version - "10.2.0.3.0"]
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288) ~[ojdbc14-10.2.0.3.0.jar:Oracle JDBC Driver version - "10.2.0.3.0"]
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:745) ~[ojdbc14-10.2.0.3.0.jar:Oracle JDBC Driver version - "10.2.0.3.0"]
at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:207) ~[ojdbc14-10.2.0.3.0.jar:Oracle JDBC Driver version - "10.2.0.3.0"]

How can I obtain information about line and column? is it possible via JDBC?

1
  • Can you post the Java code that didn't provide you with the wanted error message? I do get this information from my 11g instance. Commented Jul 22, 2015 at 12:03

4 Answers 4

2

I'm not aware of any third party library, which will help you to achieve this. But, as far as I know about SQLException, you can't.

And BTW, You are getting above error, because you haven't created table/view, which you were trying to access.

Sign up to request clarification or add additional context in comments.

3 Comments

yes, I know that table is absent. I am trying to figure out how to get in JDBC table name which is absent.
Please visit the link, which I have included in my answer. Probably, you will find the answer, which you were looking for. :/
I found workaround. If wrap code with begin ... end, SQLException will contain line number and column
2

SQLException.getCause() gives you the position of the character at which the exception originated:

    select * from blahblahblah

    Error : 942, Position : 14, Sql = select * from blahblahblah, OriginalSql = select * from blahblahblah, Error Msg = ORA-00942: table or view does not exist

So you could parse the cause and get the character index, then compute the line number and the column number.

This goes for JDBC version 12.2.0.1 and Oracle 12c, not sure about other versions.

Comments

0

From the Command Line, we can execute multiple SQL queries at a time. So, while execution if we get any error, command line processor gives "Line" and "Column" to help the user to know about the faulty line. Anyways, Its a utility provided by Database.

However, In JDBC you can either execute a single query or execute the batch of statements. In both cases you won't get any Line Number and Column Number because its not useful in any sense. Though you can get the reason of error and code, based on your JDBC driver.

2 Comments

The question is : if I get ORA-00942 while running code via JDBC how I get name of table which does not exists? If I can retrieve line number and column, I can do that
You will not get the Line Number in JDBC. You have to work with SQL State and Error Code from the SQLException, if table does not exist. But these values are vendor specific.
0

I solved this in Python by using the offset (# chars) to determine what line the error happened on. This can be done by looping through the original sql statement and counting the lines while also keeping track of the number of characters seen so far.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.