JDBC DatabaseMetaData.getColumns() returns duplicate columns

前端 未结 5 1329
南方客
南方客 2020-12-15 19:17

I\'m busy on a piece of code to get alle the column names of a table from an Oracle database. The code I came up with looks like this:

DriverManager.register         


        
5条回答
  •  眼角桃花
    2020-12-15 19:58

    In oracle, Connection.getMetaData() returns meta-data for the entire database, not just the schema you happen to be connected to. So when you supply null as the first two arguments to meta.getColumns(), you're not filtering the results for just your schema.

    You need to supply the name of the Oracle schema to one of the first two parameters of meta.getColumns(), probably the second one, e.g.

    meta.getColumns(null, "myuser", "EMPLOYEES", null);
    

    It's a bit irritating having to do this, but that's the way the Oracle folks chose to implement their JDBC driver.

提交回复
热议问题