문제

I am using java.sql.DatabaseMetaData#getTables per this JavaDoc.

What should I use for the tableNamePattern if I want to look up a table and ignore case? Where is this pattern format documented?

Can I craft a pattern here that will match "loinc", "LOINC", or "Loinc"?

도움이 되었습니까?

해결책

Can I craft a pattern here that will match "loinc", "LOINC", or "Loinc"?

In general: No. The JDBC API does not offer a way to perform a case-insensitive query for a specific table.

In practice this is often not a problem, as most DBMS' use only upper case for table names. The ANSI SQL standard requires table names in SQL queries be converted to upper case, unless they are quoted (using "). Since constantly quoting is rather tedious, most developers and most software use table names in upper case. So in most situations you can just assume the table name is in upper case, and use a pattern in upper case.

If you really need a case-insensitive query, you can specify a tableNamePattern of null (which means not to filter by name), then iterate through all the results and check the table name in Java code. Just be aware that this may be slow for databases with very many tables.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top