Tag Archives: Spring

Spring Boot Main Class Configuration


A spring boot application starts from the main class (class with main() method) that contains main method with below signature. On Startup of spring boot application it create Spring ApplicationContext and beans also for application..

@SpringBootApplication
public class SpringBootMainClassApplication {
    public static void main(String[] args) {
        SpringApplication.run(SpringBootMainClassApplication.class, args);
    }
}

By default spring boot search the main class in the class path at compile time. if it’s find multiple main class or none then it will throw exception as below.

Spring Boot Application without Main class

While running the application through STS/Eclipse it will show popup as “Selection does not contain a main type”.

Spring Boot Application without Main Class

Spring Boot Application with multiple main class

If you run the application manually through STS/Eclipse then you have to select one of the Main class below before execution. If you are trying to maven package of install from CMD it will throw exception as below.

mvn package -Dmaven.test.skip=true

it will through exception as below in CMD.

Spring Boot Application with Multiple Main Class

Solutions

To start a Spring Boot application, it’s mandatory to specify one Main class in your class path. If there is one Main class as above then will not be any issue to start a Spring boot application.

Now if there are multiple main class in your Spring Boot application then below solutions will help to start your application.

Solution 1: Specify the Main class in pom.xml properties

You can specify your main class in property start-class as below.

<properties>
      <!-- The spring boot main class to start by executing "java -jar" -->
      <start-class>com.FacingIssuesOnIT.SpringBootMainClassApplication</start-class>
</properties>

Note : This property configuration will help only when you added the spring-boot-starter-parent as in your pom.xml otherwise follow the solutions 2 or 3 to configure the main class.

Solution 2 : Specify the Main class in spring-boot-maven-plugin of pom.xml

You can also specify the main class of Spring Boot in spring-boot-maven-plugin of pom.xml as below:

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>             
            <configuration>    
                <mainClass>com.FacingIssuesOnIT.SpringBootMainClassApplication</mainClass>
            </configuration>
        </plugin>
    </plugins>
</build>

Solution 3: Specify the Main Class on run time through CLI

You can also specify the Spring Boot Main class on runtime through CLI as below:

java -cp spring-boot-app.jar -Dloader.main=com.FacingIssuesOnIT.SpringBootMainClassApplication org.springframework.boot.loader.PropertiesLauncher

By using any of these configuration, You can decide you Spring Boot application main class for start the application.

Conclusion

In this post you learn about the different way to configure Spring Boot Application main class to start the application if your application having multiple Main classes.

Let me know your thoughts on this post.

Happy Learning !!!

[Solved] Spring Boot IllegalStateException: Ambiguous mapping. Cannot map ‘XYZController’ method


In Spring Boot Rest/MVC application, we got this exception “java.lang.IllegalStateException: Ambiguous mapping. Cannot map ‘XYZController’ method” which will not allow to create bean for your controller and also throw “UnsatisfiedDependencyException: Error creating bean with name XYZ” as given in below stack trace.

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'documentationPluginsBootstrapper' defined in URL [jar:file:/C:/Users/saurabh.gupta14/.m2/repository/io/springfox/springfox-spring-web/2.4.0/springfox-spring-web-2.4.0.jar!/springfox/documentation/spring/web/plugins/DocumentationPluginsBootstrapper.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'webMvcRequestHandlerProvider' defined in URL [jar:file:/C:/Users/saurabh.gupta14/.m2/repository/io/springfox/springfox-spring-web/2.4.0/springfox-spring-web-2.4.0.jar!/springfox/documentation/spring/web/plugins/WebMvcRequestHandlerProvider.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'helloController' method 
com.FacingIssuesOnIT.controller.HelloController#sayHello()
to {GET [/api/FacingIssuesOnIT]}: There is already 'helloController' bean method
com.FacingIssuesOnIT.controller.HelloController#sayHiHello() mapped.
	at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:800) ~[spring-beans-5.3.9.jar:5.3.9]
	at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:229) ~[spring-beans-5.3.9.jar:5.3.9]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1354) ~[spring-beans-5.3.9.jar:5.3.9]
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'webMvcRequestHandlerProvider' defined in URL [jar:file:/C:/Users/saurabh.gupta14/.m2/repository/io/springfox/springfox-spring-web/2.4.0/springfox-spring-web-2.4.0.jar!/springfox/documentation/spring/web/plugins/WebMvcRequestHandlerProvider.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'helloController' method 
com.FacingIssuesOnIT.controller.HelloController#sayHello()
to {GET [/api/FacingIssuesOnIT]}: There is already 'helloController' bean method
com.FacingIssuesOnIT.controller.HelloController#sayHiHello() mapped.
	at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:800) ~[spring-beans-5.3.9.jar:5.3.9]
	at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:229) ~[spring-beans-5.3.9.jar:5.3.9]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1354) ~[spring-beans-5.3.9.jar:5.3.9]
	... 24 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'helloController' method 
com.FacingIssuesOnIT.controller.HelloController#sayHello()
to {GET [/api/FacingIssuesOnIT]}: There is already 'helloController' bean method
com.FacingIssuesOnIT.controller.HelloController#sayHiHello() mapped.
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1786) ~[spring-beans-5.3.9.jar:5.3.9]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:602) ~[spring-beans-5.3.9.jar:5.3.9]
		... 41 common frames omitted
Caused by: java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'helloController' method 
com.FacingIssuesOnIT.controller.HelloController#sayHello()
to {GET [/api/FacingIssuesOnIT]}: There is already 'helloController' bean method
com.FacingIssuesOnIT.controller.HelloController#sayHiHello() mapped.
	at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$MappingRegistry.validateMethodMapping(AbstractHandlerMethodMapping.java:665) ~[spring-webmvc-5.3.9.jar:5.3.9]
	at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$MappingRegistry.register(AbstractHandlerMethodMapping.java:631) ~[spring-webmvc-5.3.9.jar:5.3.9]
	at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.registerHandlerMethod(AbstractHandlerMethodMapping.java:328) ~[spring-webmvc-5.3.9.jar:5.3.9]
		... 55 common frames omitted

Reason of Exception

The exception “java.lang.IllegalStateException: Ambiguous mapping. Cannot map ‘xyzController’ method” is throw when there is end point of REST urls of two method are same with Verb in your application. So on time of deploy your spring boot application the dispatcher servlet will create mapping of urls with respect to method because two methods having the same name with http verb (GET/POST/PUT/DELETE) then dispatcher got confuse for particular url which method need to point and throw this exception “java.lang.IllegalStateException: Ambiguous mapping”.

Solution

As explained above the reason of this exception. Once this exception happen check for the recently added urls for REST services . This url can be same with in same controller of your application where the exception occurred or match with other controller if no request mapping on class level.

Let me know your thoughts on it.

Happy Learning !!!

Spring Boot Banner Customization Enable / Disable


In Spring Boot by default configure for Banner “Spring Boot” as below which will display on your console with version number.

Spring Boot Banner

Possible Values for Spring Boot Banner

Spring Boot support these three types of configuration for Banner:

  • OFF : Disable printing of Banner
  • CONSOLE : Display Banner to System.out
  • LOG : Display Banner on your Log also.

How to set these Spring Boot Banner Configuration?

There are two ways to configure Spring Boot Banner:

  • Banner setting by application.properties / applictaion.yml

You can add this property in application.properties/ application.yml file to change in configuration of Banner. If you set as off will not display in console and log.

application.properties

##possible values off, console, log
spring.main.banner-mode=console

application.yml

##possible values off, console, log
spring
  main
    banner-mode:console
  • Banner Setting in Spring Boot main() method

You can also change in Spring Boot class main() method to set Banner configuration as below in this case no setting required on application properties file.

Spring Boot Banner Setting
  • Customize Spring Boot Banner

By default Spring Boot show default banner “Spring Boot” with version number. If you want to customize this banner and replace it then create one banner.txt file and place it on your Spring boot application resource folder.

Example:

${Ansi.RED}                  $$$        $$$$$      $$$$         $$$$     $$$$$
${Ansi.GREEN}                  $$$       $$$$$$$     $$$$         $$$$    $$$$$$$
${Ansi.BLUE}                  $$$       $$$$$$$     $$$$$       $$$$$    $$$$$$$
${Ansi.RED}                  $$$       $$$$$$$      $$$$       $$$$     $$$$$$$
${Ansi.GREEN}                  $$$      $$$$ $$$$     $$$$$     $$$$$    $$$$ $$$$
${Ansi.BLUE}                  $$$      $$$$ $$$$      $$$$     $$$$     $$$$ $$$$
${Ansi.RED}                  $$$     $$$$$ $$$$$     $$$$     $$$$    $$$$$ $$$$$
${Ansi.GREEN}                  $$$     $$$$   $$$$     $$$$$   $$$$$    $$$$   $$$$
${Ansi.BLUE}                  $$$     $$$$   $$$$      $$$$   $$$$     $$$$   $$$$
${Ansi.RED}                  $$$    $$$$$   $$$$$     $$$$$ $$$$$    $$$$$   $$$$$
${Ansi.GREEN}                  $$$    $$$$$$$$$$$$$      $$$$ $$$$     $$$$$$$$$$$$$
${Ansi.BLUE}          $$$$   $$$$    $$$$$$$$$$$$$      $$$$ $$$$     $$$$$$$$$$$$$
${Ansi.RED}          $$$$   $$$$   $$$$$$$$$$$$$$$      $$$$$$$     $$$$$$$$$$$$$$$
${Ansi.GREEN}          $$$$$ $$$$$   $$$$       $$$$      $$$$$$$     $$$$       $$$$
${Ansi.BLUE}          $$$$$$$$$$$  $$$$$       $$$$$     $$$$$$$    $$$$$       $$$$$
${Ansi.RED}           $$$$$$$$$   $$$$         $$$$      $$$$$     $$$$         $$$$
${Ansi.GREEN}            $$$$$$$    $$$$         $$$$      $$$$$     $$$$         $$$$

${Ansi.RED} :: Spring Boot${spring-boot.formatted-version} :: ${Ansi.DEFAULT}

Once you will run your application will show updated banner as below.

Customize Spring Boot Banner

Let me know your thoughts on it.

Happy Learning !!!

[Solved] Spring Data JPA :QueryCreationException: Could not create query for public abstract method XYZ


In Spring boot Data JPA this exception QueryCreationException occurred when there is auto creation of Query or mismatch or column name in column/property in Entity class.

Spring Data JPA supports two ways of creating auto generation of query:

  • JQL in Spring data JPA or HQL when using the Hibernate.
  • Spring Data methods in Repository interface for Example : findByUserName() or findByUserNameOrDesignation() etc.

Reason for Exception

Spring Data JPA generate queries based on name of property in your Entity class , If entity based custom methods defined in repository interfaces also generate queries internally based on method name.

If there is any mismatch or incorrect name in custom methods of repository interface when comparing to entity class properties then on compile time it will not through any issue but when you run or deploy spring boot application will through QueryCreationException: Could not create query for method XYZ.

For Example : In User Entity class there is property userName while in custom methods in repository, you are trying to get detail from method findByName() so this property name not exist in User Entity class . Till compile time this method will not show any issue and compile successfully while on deploy time because using Spring Data JPA so will try to fetch data by Name and it will through exception as QueryCreationException: Could not create query for method XYZ.

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userController': Unsatisfied dependency expressed through field 'userrepo'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository' defined in com.FacingIssuesOnIT.repository.UserRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Invocation of init method failed; nested exception is org.springframework.data.repository.query.QueryCreationException: Could not create query for public abstract java.util.Optional com.FacingIssuesOnIT.repository.UserRepository.findByUsername(java.lang.String)! Reason: Failed to create query for method public abstract java.util.Optional com.FacingIssuesOnIT.repository.UserRepository.findByUsername(java.lang.String)! No property username found for type User!; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.Optional com.FacingIssuesOnIT.repository.UserRepository.findByUsername(java.lang.String)! No property username found for type User!
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:660) ~[spring-beans-5.3.9.jar:5.3.9]
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:640) ~[spring-beans-5.3.9.jar:5.3.9]
	Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository' defined in com.FacingIssuesOnIT.repository.UserRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Invocation of init method failed; nested exception is org.springframework.data.repository.query.QueryCreationException: Could not create query for public abstract java.util.Optional com.FacingIssuesOnIT.repository.UserRepository.findByUsername(java.lang.String)! Reason: Failed to create query for method public abstract java.util.Optional com.FacingIssuesOnIT.repository.UserRepository.findByUsername(java.lang.String)! No property username found for type User!; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.Optional com.FacingIssuesOnIT.repository.UserRepository.findByUsername(java.lang.String)! No property username found for type User!
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1786) ~[spring-beans-5.3.9.jar:5.3.9]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:602) ~[spring-beans-5.3.9.jar:5.3.9]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:524) ~[spring-beans-5.3.9.jar:5.3.9]
		... 25 common frames omitted
Caused by: org.springframework.data.repository.query.QueryCreationException: Could not create query for public abstract java.util.Optional com.FacingIssuesOnIT.repository.UserRepository.findByUsername(java.lang.String)! Reason: Failed to create query for method public abstract java.util.Optional com.FacingIssuesOnIT.repository.UserRepository.findByUsername(java.lang.String)! No property username found for type User!; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.Optional com.FacingIssuesOnIT.repository.UserRepository.findByUsername(java.lang.String)! No property username found for type User!
	at org.springframework.data.repository.query.QueryCreationException.create(QueryCreationException.java:101) ~[spring-data-commons-2.5.3.jar:2.5.3]
	at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.lookupQuery(QueryExecutorMethodInterceptor.java:106) ~[spring-data-commons-2.5.3.jar:2.5.3]
	at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.lambda$mapMethodsToQuery$1(QueryExecutorMethodInterceptor.java:94) ~[spring-data-commons-2.5.3.jar:2.5.3]
			... 35 common frames omitted
Caused by: java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.Optional com.FacingIssuesOnIT.repository.UserRepository.findByUsername(java.lang.String)! No property username found for type User!
	at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.<init>(PartTreeJpaQuery.java:96) ~[spring-data-jpa-2.5.3.jar:2.5.3]
	at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:107) ~[spring-data-jpa-2.5.3.jar:2.5.3]
		... 57 common frames omitted
Caused by: org.springframework.data.mapping.PropertyReferenceException: No property username found for type User!
	at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:90) ~[spring-data-commons-2.5.3.jar:2.5.3]
	at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:437) ~[spring-data-commons-2.5.3.jar:2.5.3]
	at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:413) ~[spring-data-commons-2.5.3.jar:2.5.3]
		... 61 common frames omitted

Solutions

To solve “QueryCreationException” in Spring boot data JPA follow these steps:

  • Go to stack trace of exception and see which query and methods of repository interface is throwing the exception.
  • Go to repository interface where this particular query and methods are defined and also check the Entity name with respect to repository.
  • Go to Entity class and check the properties name defined in method/queries are same or not.
  • If it’s not same or some typing mistake then only you will get this exception.

Note: Whenever you change any property name / column name in Entity class then always check for dependency in Native Queries/ JQL/HQL and Custom methods in repository otherwise your application will not deploy and fail on runtime.

Let me know your thoughts on it.

Happy Learning !!!

[Solved] javax.portlet.PortletException: Error occured during request processing: INSTANCE


This exception happened with web application or using rest services with Spring. In my case it was occurred with rest services using with Spring. It was because of conflict between old and new version of httpclient.jar and httpcore.jar. I was using latest version in my pom.xml while due to other jar dependency while deploy application added others older version jar.


javax.portlet.PortletException: Error occured during request processing: INSTANCE
    at org.springframework.web.portlet.DispatcherPortlet.doRenderService(DispatcherPortlet.java:805)
    at org.springframework.web.portlet.FrameworkPortlet.processRequest(FrameworkPortlet.java:536)
    at org.springframework.web.portlet.FrameworkPortlet.doDispatch(FrameworkPortlet.java:483)
    at javax.portlet.GenericPortlet.render(GenericPortlet.java:233)
    at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:100)
    at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:64)
    at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:111)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:72)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:73)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
    at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:593)
    at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:530)

Solution

I resolved this issue after reaching to lib folder of my web application deployment location:

Steps 1: Removed older version jars for httpclient and httpcore from lib directory.

Step 2: Restart the server.

INstance not found issue
Solution for javax.portlet.PortletException: Error occured during request processing: INSTANCE

My issue was resolved after following above two steps.

Know More

To know more about Java Exception Hierarchy, in-built exception , checked exception, unchecked exceptions and solutions. You can learn about Exception Handling in override methods and lots more. You can follow below links:  s

[Solved] JDBC, “Invalid argument value: java.io.NotSerializableException; nested exception is java.sql.SQLException”


JDBC “java.io.NotSerializableException” occurs while using Spring JDBC Template for connectivity and passing arguments for searching/update as parameters. Because JDBC parameters always required searialize objects.

Mostly happen when forget to use get fields value from object and class is not serializable.

Example :

Exception Message

Invalid argument value: java.io.NotSerializableException; nested exception is java.sql.SQLException: Invalid argument value: java.io.NotSerializableException

Class using

public class DynamicDashboard {
private int dashboardId;
private String dashboardName;
private String htmlContent;
private String scriptContent;
private String ruleContent;

public DynamicDashboard()
{
	super();
}

//Getter and Setters

Below is my DAO class method where this exception occured  for column RULE_CONTENT.

public void addDashboard(DynamicDashboard dynamicDashboard) {
		String sql = "INSERT INTO dynamic_dashboard "
				+ "(DASHBOARD_NAME, HTML_CONTENT,SCRIPT_CONTENT,RULE_CONTENT) VALUES (?, ?, ?,?)";

		try {
			jdbcTemplate = new JdbcTemplate(dataSource);

			jdbcTemplate.update(sql,
					new Object[] { dynamicDashboard.getDashboardName(), dynamicDashboard.getHtmlContent(),
							dynamicDashboard.getScriptContent(), dynamicDashboard});
		} catch (Exception ex) {
			logger.error(ex.getMessage());
		}

	}

In above method we forget to get last parameter value for rule like dynamicDashboard.getRuleContent()for database column RULE_CONTENT because JDBCTemplate always required serializable object and all wrapper classes(Integer, String etc.) are searializable. It will through exception “java.io.NotSerializableException” as above.

Solution :

Add get method for ruleContent for object dynamicDashboard.

Correct Code

public void addDashboard(DynamicDashboard dynamicDashboard) {
		String sql = "INSERT INTO dynamic_dashboard "
				+ "(DASHBOARD_NAME, HTML_CONTENT,SCRIPT_CONTENT,RULE_CONTENT) VALUES (?, ?, ?,?)";

		try {
			jdbcTemplate = new JdbcTemplate(dataSource);

			jdbcTemplate.update(sql,
					new Object[] { dynamicDashboard.getDashboardName(), dynamicDashboard.getHtmlContent(),
							dynamicDashboard.getScriptContent(), dynamicDashboard.getRuleContent()});
		} catch (Exception ex) {
			logger.error(ex.getMessage());
		}

	}

More Issues

For more JDBC issue solution follow link Common JDBC Issues.

Leave you feedback to enhance more on this topic so that make it more helpful for others.