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 ...
                
            
       
        
            
                11
            
            votes
        
        
            
        JavaFX app with User Authentication and SQL Persistence
                    superfluous comments
    // region Main Methods
    ...
    // endregion [Main Methods]
    // region Utils
    ...
    // endregion [private utility methods]
...
                
            
       
        
            
                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 ...
                
            
       
        
            
                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 ...
                
            
       
        
            
                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 ...
                
            
       
        
            
                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 ...
                
            
       
        
            
                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 ...
                
            
       
        
            
                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 ...
                
            
       
        
            
                5
            
            votes
        
        
        First Java Program: A Basic GUI Library Management System with JavaFX
                    All of the Buttons go unused:
...
                
            
       
        
            
                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 ...
                
            
       
        
            
                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 ...
                
            
       
        
            
                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++.
...
                
            
       
        
            
                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 ...
                
            
       
        
            
                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 ...
                
            
       
        
            
                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.
...
                
            
       
        
            
                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 ...
                
            
       
        
            
                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 ...
                
            
       
        
            
                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, ...
                
            
       
        
            
                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.
...
                
            
       
        
            
                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 ...
                
            
       
        
            
                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:
...
                
            
       
        
            
                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 <...
                
            
       
        
            
                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, ...
                
            
       
        
            
                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:
...
                
            
       
        
            
                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 ...
                
            
       
        
            
                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
...
                
            
       
        
            
                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 ...
                
            
       
        
            
                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 ...
                
            
       
        
            
                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.
...
                
            
       
        
            
                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 ...
                
            
       
        Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
jdbc × 86java × 78
sql × 13
mysql × 13
performance × 9
database × 9
spring × 8
beginner × 7
swing × 6
oracle × 6
authentication × 4
connection-pool × 4
kotlin × 3
sqlite × 3
javafx × 3
object-oriented × 2
hash-map × 2
error-handling × 2
homework × 2
mvc × 2
e-commerce × 2
minecraft × 2
jpa × 2
jython × 2
python × 1