Java - Statement (JDBC)
Go to solution
Solved by Jisagi,
It doesn't really matter which way you do it. There are a lot of good online tutorials which suggest the one or the other way. The official oracle java doc lists a new Statement object inside a method, but since the example only displays one method and not the whole class, it might only be for the examples sake. In the end, both ways will work just fine.
The connection object on the other hand can/should be held as class or instance variable (or as method argument) and not inside each new method. If you want Statements on a (pure) local scope inside each method, you could use PreparedStatements and omit normal Statements completely.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now