Skip to content

Instantly share code, notes, and snippets.

@maizhibin
Created September 12, 2013 14:38
Show Gist options
  • Save maizhibin/6538540 to your computer and use it in GitHub Desktop.
Save maizhibin/6538540 to your computer and use it in GitHub Desktop.
Use jdbc execute query
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
//System.out.println(((DruidDataSource) ((LazyConnectionDataSourceProxy)
//SpringUtils.getBean("dataSource")).getTargetDataSource()).getRawJdbcUrl());
String sql = "select * from erp_user where login_id=? and password=?";
conn = DBUtil.getConnection();
stmt = conn.prepareStatement(sql);
stmt.setString(1, "name");
stmt.setString(2, "password");
rs = stmt.executeQuery();
while (rs.next()){
System.out.println(rs.getString("name"));
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
DBUtil.close(rs, stmt, conn);
} catch (SQLException e) {
e.printStackTrace();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment