If you have used PreparedStatement with parameterized query (with question marks) and forget to set those parameters you will get an SQLException.
Example:String insertQuery ="insert into employees values(?,?)";
Connection connection = DriverManager.getConnection(url,userName,password);
PreparedStatement preparedStatement = connection.prepareStatement(insertQuery);
preparedStatement.execute();
As you can see the PreparedStatement is executed without setting the query parameters.
SolutionPreparedStatement preparedStatement = connection.prepareStatement(insertQuery);
preparedStatement.setString(1, "Micheal"); //Name
preparedStatement.setString(2, "IT"); //Dept
preparedStatement.execute();
You can download this article in various formats for your convenience. Choose from the options below:
Facing issues? Have Questions? Post them here! I am happy to answer!
- Java Jackson ObjectMapper Class with Examples
- How to add a Delay of a Few Seconds in Java Program
- Java SE JDBC Select Statement Example
- How to Word-Warp Console logs in IntelliJ
- Convert Java Array to ArrayList Code Example
- [Java] Error: Unmappable character for encoding UTF-8. Save could not be completed.
- Maven BUILD FAILURE: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin
- How to extract Java Jar/War/Ear files in Linux
- Java: Convert String to Binary
- Java Generics: Type parameter cannot be instantiated directly
- How to Create and Run a Command Line Application using Spring Boot
- How to Convert a Java Object into an Optional with Example
- [Hibernate] The method buildSessionFactory() from the type Configuration is deprecated
- How to Set JAVA_HOME PATH to Mac .zshrc profile file
- Formatting Double in Java [Examples]
- Java 8: Stream map with Code Examples
- Fix: SyntaxError: ( was never closed [Python]
- Java Split String by Spaces
- [fix] Java JDBC SQLSyntaxErrorException: Unknown database
- Fix: SpringFramework BeanDefinitionValidationException: Could not find an init method named
- Java Date Time API: LocalDateTime get(TemporalField field) examples
- How to create Date in yyyy-MM-dd format in Java
- Java: Create Temporary Directory and File and Delete when application terminates
- Fix RabbitMQ: AuthenticationFailureException: ACCESS_REFUSED
- Run Java Code Every Second
- Java Generics explained with simple definition and examples - Java
- How to run a Maven jar project from eclipse without tomcat - Eclipse
- Chrome : When Adobe flash player has finished updating, reload this page to active it - Chrome
- How to change the font in TextEdit on Mac - MacOS
- How to Install MongoDB in VSCode - HowTos
- [Fix] reCAPTCHA not working in Web Browser - Google
- Get HTML table td, tr or th inner content value with id or name attribute - Html
- Free Unlimited Calls from MTNL & BSNL Landlines from 1st May 2015 - HowTos