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