2 Replies Latest reply on Feb 4, 2020 8:00 PM by Tony007

    error connecting to database

    Tony007

      hi am trying to connect to database with my hava application am geting this error

      am geting this error

      log4j:WARN No appenders could be found for logger (org.jboss.logging).

      log4j:WARN Please initialize the log4j system properly.

      log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

      21421 [main] INFO com.co.za.jdbc.DBConnection - Starting DBConnection on hostname with PID 11112 (C:\eclipseproj\App\bin started byusername in C:\eclipseproj\App)

      21422 [main] INFO com.co.za.jdbc.DBConnection - The following profiles are active: @spring.profiles.active@

      29662 [main] WARN org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start reactive web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ReactiveWebApplicationContext due to missing ReactiveWebServerFactory bean.

      29675 [main] INFO org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLoggingListener -

       

       

      Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.

      29678 [main] ERROR org.springframework.boot.SpringApplication - Application run failed

      org.springframework.context.ApplicationContextException: Unable to start reactive web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ReactiveWebApplicationContext due to missing ReactiveWebServerFactory bean.

      at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.onRefresh(ReactiveWebServerApplicationContext.java:81)

      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:544)

      at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:66)

      at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747)

      at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)

      at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)

      at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)

      at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)

      at com.co.za.jdbc.DBConnection.main(DBConnection.java:16)

      Caused by: org.springframework.context.ApplicationContextException: Unable to start ReactiveWebApplicationContext due to missing ReactiveWebServerFactory bean.

      at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.getWebServerFactoryBeanName(ReactiveWebServerApplicationContext.java:100)

      at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.createWebServer(ReactiveWebServerApplicationContext.java:88)

      at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.onRefresh(ReactiveWebServerApplicationContext.java:78)

      ... 8 more

       

      this my code

      package com.co.za.jdbc;
      
      
      import java.sql.Connection;
      import java.sql.DriverManager;
      
      
      import org.springframework.boot.SpringApplication;
      import org.springframework.boot.autoconfigure.SpringBootApplication;
      
      
      
      
      @SpringBootApplication
      public class DBConnection {
      
      
      public static void main(String[] args) {
      // TODO Auto-generated method stub
      
      SpringApplication.run(DBConnection .class, args);
      String jdbcUrl = "jdbc:oracle:thin:@hostname:1521/dbname.world";
      String user = "username";
      String pass = "password";
      try {
      System.out.println("connected " + jdbcUrl);
      
      Connection myconn = DriverManager.getConnection(jdbcUrl,user,pass);
      
      System.out.println("Connection succeful");
      }
      catch(Exception exec ) {
      exec.printStackTrace();
      }
      
      
      }
      
      
      }
      
        • 1. Re: error connecting to database
          Nirmala Sundarappa-Oracle

          Can you check out the springboot example on github?

          • 2. Re: error connecting to database
            Tony007

            am still geting error i used you example

             

            log4j:WARN No appenders could be found for logger (org.jboss.logging).

            log4j:WARN Please initialize the log4j system properly.

            log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

             

             

              .   ____          _            __ _ _

            /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \

            ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \

            \\/  ___)| |_)| | | | | || (_| |  ) ) ) )

              '  |____| .__|_| |_|_| |_\__, | / / / /

            =========|_|==============|___/=/_/_/_/

            :: Spring Boot ::        (v2.2.1.RELEASE)

             

             

            1054 [main] INFO appname - Starting app on Desmand-PC with PID 3400 (C:\projects\proj\app\bin started by user in C:\projects\proj\app)

            1055 [main] INFO appname - No active profile set, falling back to default profiles: default

            1910 [main] WARN org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start reactive web server; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [NocIigJDBCTemplate] for bean with name 'NocIigJDBCTemplate' defined in URL [file:/C:/projects/proj/app/bin/AppConfig.xml]; nested exception is java.lang.ClassNotFoundException: NocIigJDBCTemplate

            1937 [main] ERROR org.springframework.boot.SpringApplication - Application run failed

            org.springframework.context.ApplicationContextException: Unable to start reactive web server; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [NocIigJDBCTemplate] for bean with name 'NocIigJDBCTemplate' defined in URL [file:/C:/projects/proj/app/bin/AppConfig.xml]; nested exception is java.lang.ClassNotFoundException: NocIigJDBCTemplate

            at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.onRefresh(ReactiveWebServerApplicationContext.java:81)

            at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:544)

            at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:66)

            at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747)

            at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)

            at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)

            at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)

            at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)

            at appname.main(app.java:17)

            Caused by: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [NocIigJDBCTemplate] for bean with name 'NocIigJDBCTemplate' defined in URL [file:/C:/projects/proj/app/bin/AppConfig.xml]; nested exception is java.lang.ClassNotFoundException: NocIigJDBCTemplate

            at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1476)

            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:682)

            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:649)

            at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1604)

            at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:520)

            at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:491)

            at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:485)

            at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.getWebServerFactoryBeanName(ReactiveWebServerApplicationContext.java:98)

            at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.createWebServer(ReactiveWebServerApplicationContext.java:88)

            at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.onRefresh(ReactiveWebServerApplicationContext.java:78)

            ... 8 more

            Caused by: java.lang.ClassNotFoundException: NocIigJDBCTemplate

            at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)

            at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)

            at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)

            at java.base/java.lang.Class.forName0(Native Method)

            at java.base/java.lang.Class.forName(Class.java:398)

            at org.springframework.util.ClassUtils.forName(ClassUtils.java:277)

            at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:456)

            at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1541)

            at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1468)

            ... 17 more

            <?xml version="1.0" encoding="UTF-8"?>

            <beans xmlns="http://www.springframework.org/schema/beans"

            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

            xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

             

            <!-- Initialization for data source -->

            <bean id="dataSource" class="oracle.ucp.jdbc.PoolDataSourceImpl">

            <property name="connectionFactoryClassName"

            value="oracle.jdbc.pool.OracleDataSource" />

            <!-- Connection URL uses a TNS alias -->

            <property name="URL" value="jdbc:oracle:thin:@lservername:1521/dbname          " />

            <property name="user" value="username" />

            <property name="password" value="pssword" />

            <property name="maxPoolSize" value="10" />

            <property name="initialPoolSize" value="5" />

            </bean>

             

            <!-- Definition for EmpJDBCTemplate bean -->

            <bean id="NocIigJDBCTemplate" class="NocIigJDBCTemplate">

            <property name="dataSource" ref="dataSource" />

            </bean>

            </beans>

            ==

            package proj.app.co.za;

             

             

            import java.util.List;

             

             

            import javax.sql.DataSource;

             

             

            import org.springframework.jdbc.core.JdbcTemplate;

             

             

            public class NocIigJDBCTemplate {

             

            private DataSource dataSource;

            private JdbcTemplate jdbcTemplate;

             

            public void setDataSource(DataSource dataSource) {

            this.dataSource = dataSource;

            this.jdbcTemplate = new JdbcTemplate(dataSource);

             

             

            }

             

            public void displayEmpList() {

            final String sql = "select iig_no,iig_desc,iig_created_date,iig_created_by,iig_modified_date,iig_modified_by from employees";

            List<NociigDAO> nociig = jdbcTemplate.query(sql, new NociigMapper());

             

             

            System.out.println(

            String.format("%20s %20s %20s %20s %20s %20s \n", "iig_no","iig_desc","iig_created_date","iig_created_by","iig_modified_date","iig_modified_by"));

             

             

             

            for (NociigDAO iig : nociig) {

            System.out.println(String.format("%20d %20s %20s %20d %20d %20d", iig.getIigNo(), iig.getIigDescripion(),

            iig.getIigCreatedBy(), iig.getIigCreateddate(), iig.getIigModifiedBy(), iig.getIigModifieddate()));

            }

            }

             

             

            }