这是我用 Apache dbutils 编写的测试程序:
public static void main(String[] args) {
Connection conn = null;
String url = "jdbc:mysql://localhost:3306/bacula";
String driver = "com.mysql.jdbc.Driver";
String user = "bacula";
String pwd = "root";
try {
DbUtils.loadDriver(driver);
conn = DriverManager.getConnection(url, user, pwd);
QueryRunner query = new QueryRunner();
List<Map<String, Object>> mapList = query.query(conn, "select * from Client", new MapListHandler());
for (Iterator<Map<String, Object>> li = mapList.iterator(); li.hasNext();) {
Map<String, Object> m = li.next();
for (Iterator<Entry<String, Object>> mi = m.entrySet().iterator(); mi.hasNext();) {
Entry<String, Object> e = mi.next();
System.out.println(e.getKey() + "=" + e.getValue());
}
}
} catch (SQLException se) {
se.printStackTrace();
} finally {
DbUtils.closeQuietly(conn);
}
}
}
输出是:
ClientId=1
Name=[B@8146158
Uname=[B@7202dc8c
AutoPrune=1
FileRetention=2592000
JobRetention=15552000
但是 Name 和 Uname 在 MySQL 中应该是“string”类型,我在哪里出错了?谢谢。