11 votes
Accepted

Simple Oracle connection using JDBC

Minor detail: I prefer putting a closing parenthesis on its own line when the content between parentheses spans more than one line. (Basically, it looks like one-true-brace style with parentheses ...
jpmc26's user avatar
  • 1,233
11 votes

Using static final Strings for SQL Query in Spring Boot

Sorry to present the antithesis to an existing answer once more: if the string is neither reusable nor public, a constant makes no sense in my book. (And yes, this question is opinion-based ;-)) I ...
mtj's user avatar
  • 4,812
6 votes

JDBC query with limit and offset

If you want to clean up a bit the method, then I think that you should try another, more object oriented way of writing the method (currently the method is written procedurally). Implementation 1 ...
RaISug's user avatar
  • 136
6 votes

Simple Oracle connection using JDBC

In addition, you should always close your ResultSet and your Statement explicitly. (Or: also use these in a try-with-resources block, and yes, both are AutoCloseable.) The background is, that these ...
mtj's user avatar
  • 4,812
6 votes
Accepted

Mapping named parameters to indices for PreparedStatement

Name of the class doesn't indicate its purpose. The class is called "ParameterMap" but its use-case (filling in values in a query) doesn't need to know about it having a map somewhere inside ...
QuasiStellar's user avatar
  • 2,229
5 votes

Simple Oracle connection using JDBC

There is one important thing you should always do if working with a database: You should always close the connection. Therefore I would suggest adding a finally ...
Heslacher's user avatar
  • 50.4k
5 votes

Java methods to add and authenticate users in MySQL

Funny coincidence, I just created the solution for your problem (but in PHP). The common thing here is the one-time use of a prepared statement, the difference is in the query string and arguments, so ...
potato's user avatar
  • 1,122
5 votes
Accepted

Searchable database with Java and SQL

Block form over statement form if (!dBfile.exists()) createNewTable(); This is a risky pattern. Say you (or someone else, perhaps a Python ...
mdfst13's user avatar
  • 21.6k
4 votes
Accepted

Storing configurations of states to a database - Breadth First Search

Prefer interfaces to implementations public static ArrayList<State> findNeighbours(State currentState) { Consider ...
mdfst13's user avatar
  • 21.6k
4 votes

Simple Oracle connection using JDBC

primitive obsession Your method has a long parameter list and all parameters are of same primitive type. (strictly speaking a String is not a primitive, but I ...
Timothy Truckle's user avatar
4 votes
Accepted

Java database query logic

Resource-leak: you neither close the statement nor the result set. Depending on the database driver, this can lead to system resource leaks, blocked OS handles, etc. Always close database objects ASAP ...
mtj's user avatar
  • 4,812
4 votes

Connection pool implementation

I didn't understand the concept here. How come ConnectionPool is a part of PooledConnection? My understanding of a pool - you a ...
Ram B Gorre's user avatar
4 votes
Accepted

Generating and storing a unique salt in Oracle database using Java

Please use best practices in general when dealing with password hashing. If you have to verify the database for your generated salt to be unique, you're using a bad salt generator. Make sure to focus ...
dfhwze's user avatar
  • 13.9k
4 votes

Java methods to add and authenticate users in MySQL

You must never store passwords as plain text in the database. Read an article about password hashing to avoid this mistake in the future. Make sure that you have a unique index on the ...
Roland Illig's user avatar
  • 21.3k
4 votes

Using static final Strings for SQL Query in Spring Boot

Not many valid reasons, why would ever isRecordExists2 be better method. It is almost always good to extract reusable strings into constants and split code into ...
K.H.'s user avatar
  • 2,668
4 votes

Mapping named parameters to indices for PreparedStatement

commenting var index = 1 // <-- JDBC starts counting with 1 Thank you for the one-origin reminder, that's a helpful comment. ...
J_H's user avatar
  • 24.8k
3 votes

JDBC query with limit and offset

I would do something similar to Alessandro's implementation but take advantage of the fact that you can chain calls to append since they also return ...
Legato's user avatar
  • 9,819
3 votes
Accepted

Java JDBC: MySQL database-wrapper

General Approach I generally do not like wrapper classes like these. They seldomly add any real functionality, they often make it impossible to use important functionality (such as prepared ...
tim's user avatar
  • 25.1k
3 votes

Transaction in spring boot

You can use Spring data CrudRepository which does a lot of things for you out of the box. Just create an interface and "map" it to the object you want to persist in the database, by writing the class ...
Urosh T.'s user avatar
  • 131
3 votes

Transaction in spring boot

Did you try to use google for this? You have multiple way to do this :P For example: @Transactional annotation on method. Or using XML file to wrap methods with ...
KirkoR's user avatar
  • 133
3 votes
Accepted

Get RSS feeds and store them into database

When using defn, the docstring goes before the arguments list, not after. In order to prevent environment coupling, functions that use a ...
Valentin Waeselynck's user avatar
3 votes

DAO to create, update, and delete a project

Nitpick public boolean create(Project project) { String id = UUID.randomUUID().toString().toUpperCase().replace("-", ""); project.setId(id); The last two ...
mdfst13's user avatar
  • 21.6k
3 votes

Slow SQL Server performance with multiple PreparedStatement loop

Here are some ideas to try: You are not closing your PreparedStatements. There might possibly be some slow down due to resource consumption or deadlock. Use the ...
Pixelstix's user avatar
  • 246
3 votes

Using static final Strings for SQL Query in Spring Boot

I agree with @mtj's answer : YAGNI, no point in making the string reusable if it's not being reused at the moment. I would want to add that in certain scenarios it may be smart to factor out only ...
Brandon LS's user avatar
3 votes

Searchable database with Java and SQL

Well there are indeed some improvements on different subjects: Conventions Java has a naming convention that use UpperCamlCase for classes, UPPER_HYPHEN_CASE for static fields. And, when applicable, ...
gervais.b's user avatar
  • 2,067
2 votes
Accepted

Connection pool for java.sql.Connection

public ConnectionPool(ConnectionCreator creator, int poolSize) { this.creator = Objects.requireNonNull(creator, "creator == null"); } You're not respecting ...
Vogel612's user avatar
  • 25.2k
2 votes

Reading SQL file using injection and utility reader

The idea to extract SQL queries from the code into in a separate resource is good in general. Its main advantage is that when there is a non-substantial change at the database side, it might be enough ...
Antot's user avatar
  • 3,647
2 votes

Using HikariCP and JDBC to store data for a Minecraft plugin

Something which occurs to me is that catching the exception and not rethrowing is a very bad practice. Printing the stack trace is helpful, it tells the consumer of your API that something went wrong, ...
Aluan Haddad's user avatar
2 votes

Methods to get single and multiple JDBC results

You can factor out the boilerplate like so: ...
abuzittin gillifirca's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible