Created
January 26, 2017 07:10
-
-
Save chethanbandi/56b5aa0ad105926271dc6d4d792ca514 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String sql = "insert into report(name, userId, config) values(?, ?, ?)"; | |
try (Connection con = dataSource.getConnection()) { | |
try (PreparedStatement preparedStatement = con.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) { | |
preparedStatement.setString(1, request.get(NAME).asText()); | |
preparedStatement.setInt(2, 0); | |
preparedStatement.setString(3, request.get(CONFIG).toString()); | |
preparedStatement.execute(); | |
ResultSet rs = preparedStatement.getGeneratedKeys(); | |
if (rs.next()) { | |
int reportId = rs.getInt(1); | |
log.info("report id is [{}]", reportId); | |
} | |
} | |
} catch (SQLException e) { | |
log.error("error", e); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment