Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LastInsertId #5

Closed
apparatusdeus opened this issue Feb 6, 2013 · 4 comments
Closed

LastInsertId #5

apparatusdeus opened this issue Feb 6, 2013 · 4 comments

Comments

@apparatusdeus
Copy link

How do you get the last insert id?

It would be handy it there was some documentation and usage examples.

@PatPeter
Copy link
Owner

PatPeter commented Feb 7, 2013

I could swear that I used this functionality from one of my previous projects, but it seems as though the library does not currently support it. I'll add it onto the 4.1 to-do.

@apparatusdeus
Copy link
Author

Thanks that would be good. I don't suppose you know a work around until then?

P.s. Sorry for using Issues, I couldn't work out how to message you directly.

@PatPeter
Copy link
Owner

PatPeter commented Feb 7, 2013

No, thank you for using issues! That's the most proper way of contacting me in regards to a bug or feature request. The workaround would be:

long key = 0;
PreparedStatement ps = sql.getConnection().prepareStatement("INSERT ...", Statement.RETURN_GENERATED_KEYS);
ps.executeUpdate();
ResultSet keys = ps.getGeneratedKeys();
if (keys.next())
key = keys.getLong(1);

Where sql is your connection variable.

@PatPeter
Copy link
Owner

This issue has been fixed in 4.1 and added to BukkitDev. However, I cannot push 4.1 to GitHub yet due to an error I am diagnosing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants