Skip to main content
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
  • 5,002
11 votes

JavaFX app with User Authentication and SQL Persistence

superfluous comments // region Main Methods ... // endregion [Main Methods] // region Utils ... // endregion [private utility methods] ...
J_H's user avatar
  • 42.3k
8 votes

JavaFX app with User Authentication and SQL Persistence

Connection Management None of the methods in the SQLUtils which creates a new Connection takes care about closing it, which is a ...
Alexander Ivanchenko's user avatar
7 votes

First Java Program: A Basic GUI Library Management System with JavaFX

Separations of Concerns You've mixed UI with the business logic. The same components are responsible for interacting with the user and communicating with the database. By doing so, you're violating ...
Alexander Ivanchenko's user avatar
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,327
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
  • 22.4k
5 votes

First Java Program: A Basic GUI Library Management System with JavaFX

Alexander Ivanchenko treated the most points. That you were aware of the need of password hashing is clear, so okay. In general I find the code advanced, assuming some non-java background, and ...
Joop Eggen's user avatar
  • 4,656
5 votes

First Java Program: A Basic GUI Library Management System with JavaFX

All of the Buttons go unused: ...
Madagascar's user avatar
  • 10.1k
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
  • 14.2k
4 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
  • 141
4 votes

Java JDBC: MySQL database-wrapper

Improvements You are using the C style array notation. This was added in the original java to be compatible with C and C++. ...
Joop Eggen's user avatar
  • 4,656
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,728
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.9k
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
  • 42.3k
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

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

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,147
3 votes
Accepted

Inserting large number of rows into database with Spring boot

It makes sense to me that JDBC with prepared statements would win that contest, as we don't have to keep re-parsing the same old SQL command. Batch size before COMMIT tends to be pretty important. ...
J_H's user avatar
  • 42.3k
3 votes
Accepted

Code to add order orderitems and payment details

you already invoke spring validation on SalesOrderSubmissionCardRequest why do you need validateRequest() method? can be replaced with ...
Sharon Ben Asher's user avatar
2 votes
Accepted

Login module with JDBC

Checking return values A mistake I see in multiple places is not checking the return values of operations. Take for example the part of getting the user ID: ...
janos's user avatar
  • 113k
2 votes

Slow SQL Server performance with multiple PreparedStatement loop

You don't even need to create a HashMap because you already have an object AgentDiffs to hold the values for you. Creating a <...
Ankit Soni's user avatar
2 votes

Country, city, and address tables for a customer

besides removal of duplication, there are other issues, more important IMO, that need addressing: Using Exceptions as control flow is considered an anti pattern. There are several reasons for this, ...
Sharon Ben Asher's user avatar
2 votes

PreparedStatement for closable recordset and connection

Starting out with your first question: no, there isn't. But you may put the result set into another nested try block. Still not super-elegant, but a bit better in my opinion: ...
mtj's user avatar
  • 5,002
2 votes

Java methods to add and authenticate users in MySQL

You should really try to use a more modern approach to closeable resources. The try-with-resources statement has been introduced in Java 7 (2011). This gets rid of all the hocus-pocus around closing ...
mtj's user avatar
  • 5,002
2 votes

Updating a huge hashmap from a resultset

there was an issue with the code, I was obligated to add the SQLException to the method, since the code was not compiling otherwise. Before ...
Doi9t's user avatar
  • 3,374
2 votes

MySQL JDBC integration into App from tutorial

I use var almost everywhere. To me, it makes the code more concise and easier to refactor. Essentially, unless it makes the code harder to read / understand I use ...
forsvarir's user avatar
  • 11.8k
2 votes
Accepted

MySQL JDBC integration into App from tutorial

You're not following Java naming conventions. Package names should be all lower case. The JDBC URL is hard coded. This should be provided as a parameter. Or better yet, provide the connection with ...
TorbenPutkonen's user avatar
2 votes
Accepted

Company management app: Extracting data with JDBC and java.sql

I have a couple of more direct alternatives. Depending of a larger context. ...
Joop Eggen's user avatar
  • 4,656
1 vote
Accepted

I have a query like this that seems complicated and I want to do it by using Java Stream Api

First off, the SQL query you are generating probably doesn't do what you want it to do. Because you using a subquery (a SELECT inside a ...
RoToRa's user avatar
  • 11.6k

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