SHOW DATABASES from jdbc
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.getMYSQLserverIP()+"/mysql?user="+cryptic.decryptString(c.getMYSQLuser()).trim()+"&password="+cryptic.decryptString(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%)");
db.add(r);
}
conn.close();
return db;
}
Is this possible? Am I doing something wrong? Or is there another way to accomplish this?
(I need a list of db's so I can run Stored Procedures in them)
I am using MySql 5.0.2
Subject
Written By
Posted
SHOW DATABASES from jdbc
March 06, 2005 01:12PM
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.