Re: SHOW DATABASES from jdbc
Posted by: Mark Matthews
Date: March 06, 2005 04:37PM

Sascha Monteiro wrote:
> Hi,
>
> I need to check which databases are present, and
> put them in an ArrayList.
> I always get a nullpointer exception, here is part
> of my code:
> public ArrayList List(cfg c){
> String url = "jdbc:mysql:";
> String driver = "com.mysql.jdbc.Driver";
> int cntX = 0;
> ArrayList db = new ArrayList();
> try {
> Class.forName(driver);
> Connection conn =
> DriverManager.getConnection(""+url+"//"+c.getMYSQL
> serverIP()+"/mysql?user="+cryptic.decryptString(c.
> getMYSQLuser()).trim()+"&password="+cryptic.de
> cryptString(c.getMYSQLpsw()).trim());
> Statement stmt = conn.createStatement();
> System.out.println("connected");
> ResultSet rs;
> String _listDB = "SHOW DATABASES LIKE 'y%'";
> rs = stmt.executeQuery(_listDB);
> while ( rs.next() ) {
> String r = rs.getString("Database (y%)");

The column won't be named 'Database (y%), which is your problem. It will be named 'Database'.

-Mark

Mark Matthews
Consulting Member Technical Staff - MySQL Enterprise Tools
Oracle
http://www.mysql.com/products/enterprise/monitor.html

Options: ReplyQuote


Subject
Written By
Posted
March 06, 2005 01:12PM
Re: SHOW DATABASES from jdbc
March 06, 2005 04:37PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.