Code example for PreparedStatement

Methods: execute, getGeneratedKeys

0
 
	public void parse(String documentPath) throws SAXException, IOException, SQLException {
		statement = connection.prepareStatement(String.format("INSERT INTO documents(id, document_name) values(DEFAULT, '%s');", documentPath),
				Statement.RETURN_GENERATED_KEYS);
 
		statement.execute();
 
		ResultSet resultSet = statement.getGeneratedKeys();
 
		if (resultSet != null && resultSet.next()) {
			newDocumentId = resultSet.getInt(1);
		} 
 
		saxParser.parse(new File(documentPath), this);
	} 
 
	@Override 
	public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
		pathStack.push(qName);
		Long newPathId = null;