Re: How to know columns names in Derby database table



"Luis Angel Fdez. Fdez." <laffdez@xxxxxxxxx> writes:

Hi!

I'm trying this:

[...]

Vector<String> vNames = new Vector<String>();
String[] names;
try {
ResultSet myRs;
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
con = DriverManager.getConnection("jdbc:derby:/home/koxo/tmp/db/tests/
ubicharge");
myRs = con.getMetaData().getColumns(null, null, "bornes", "%");
while (myRs.next()) {
String str = myRs.getString("COLUMN_NAME");
vNames.add(str);
}
} catch (SQLException sqle) {
System.out.println(sqle.toString());
}
catch(Exception e) {
System.out.println("getColumnNames: "+e.toString());
e.printStackTrace();
}

[...]

The connection is made, and the 'bornes' table exists, but the loop is
never executed. What's wrong?

Derby stores table names as upper case, even if you create the table
with lower case. That is,

create table bornes(...);

is equivalent to

CREATE TABLE BORNES(...);

If you read the javadoc for DatabaseMetaData.getColumns() carefully you'll
see that the third argument, the table name pattern, "must match the
table name as it is stored in the database". Hence you must use upper
case in the metadata call, i.e.

con.getMetaData().getColumns(null, null, "BORNES", "%");

should work.

PS: For derby-specific questions it is usually better to ask on the
derby-user mailing list.

HTH

--
dt
.



Relevant Pages

  • How to know columns names in Derby database table
    ... String[] names; ... ResultSet myRs; ... } catch (SQLException sqle) { ... The connection is made, and the 'bornes' table exists, but the loop is ...
    (comp.lang.java.databases)
  • Re: How to use the UNIX command: tr
    ... > "Does anyone know how to convert a lower case string to upper case ... > Which ignores the OPs question, even though the poster is obviously ... I'm sorry, that is my response, taken out of context. ...
    (comp.unix.solaris)
  • Re: How to use the UNIX command: tr
    ... > I know very well they are POSIX compliant keywords. ... "Does anyone know how to convert a lower case string to upper case ... Which ignores the OPs question, even though the poster is obviously ...
    (comp.unix.solaris)
  • How to add a string to a big file in csharp !
    ... I want to add a string to the file and the file is sort by letter! ... string str = sr.ReadLine; ... long upper = fs.Length - 1; ... the FileStream is fitable in it? ...
    (microsoft.public.dotnet.languages.csharp)
  • How to add a string to a big file in csharp !
    ... want to add a string to the file and the file is sort by letter! ... Just after "cabbage" and at the front ... string str = sr.ReadLine; ... long upper = fs.Length - 1; ...
    (microsoft.public.dotnet.general)