I can not connect to the database via jdbc

Product summary: - IDE: Eclipse - Build: Maven - Framework: Vaadin - Server: WildFly 10.0.0 

Added all necessary drivers to the lib folder and dependency pom.xml

Created class DatabaseHelper

 @SuppressWarnings("serial") public class DatabaseHelper implements Serializable { private JDBCConnectionPool connectionPool = null; private static ResourceBundle bundle = ResourceBundle.getBundle("rts.data.databaseHelper"); public DatabaseHelper() { initConnectionPool(); } private void initConnectionPool() { try { connectionPool = new SimpleJDBCConnectionPool("org.postgresql.Driver",bundle.getString("connectionUri") ,bundle.getString("userName"), bundle.getString("password"), 2, 2); } catch (SQLException e) { e.printStackTrace(); } } public JDBCConnectionPool getConnectionPool() { return connectionPool; } } 

Created properties: databaseHelper.properties

 connectionUri=jdbc:postgresql://localhost:5432/db.risk userName=postgres password=******* 

The DatabaseHelper class and properties databaseHelper are in the same package rts.data

Now I run WildFly in the console window and get errors:

  18:00:56,015 WARN [org.jboss.modules] (default task-6) Failed to define class rts.data.databaseHelper in Module "deployment.OR.war:main" from Service Module Loader: java.lang.NoClassDefFoundError: Failed to link rts/data/databaseHelper (Module "deployment.OR.war:main" from Service Module Loader): rts/data/databaseHelper (wrong name: rts/data/DatabaseHelper) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:446) at org.jboss.modules.ModuleClassLoader.loadClassLocal(ModuleClassLoader.java:274) at org.jboss.modules.ModuleClassLoader$1.loadClassLocal(ModuleClassLoader.java:78) at org.jboss.modules.Module.loadModuleClass(Module.java:605) at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190) at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:363) at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:351) at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:93) at java.util.ResourceBundle$Control.newBundle(ResourceBundle.java:2640) at java.util.ResourceBundle.loadBundle(ResourceBundle.java:1501) at java.util.ResourceBundle.findBundle(ResourceBundle.java:1465) at java.util.ResourceBundle.findBundle(ResourceBundle.java:1419) at java.util.ResourceBundle.findBundle(ResourceBundle.java:1419) at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1361) at java.util.ResourceBundle.getBundle(ResourceBundle.java:773) at rts.data.DatabaseHelper.<clinit>(DatabaseHelper.java:13) at rts.appUI.MyUI.init(MyUI.java:39) at com.vaadin.ui.UI.doInit(UI.java:693) at com.vaadin.server.communication.UIInitHandler.getBrowserDetailsUI(UIInitHandler.java:216) at com.vaadin.server.communication.UIInitHandler.synchronizedHandleRequest(UIInitHandler.java:74) at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:41) at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1436) at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:380) at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85) at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129) at io.undertow.websockets.jsr.JsrWebSocketFilter.doFilter(JsrWebSocketFilter.java:129) at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60) at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131) at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84) at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62) at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131) at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46) at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64) at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60) at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77) at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50) at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:284) at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:263) at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81) at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:174) at io.undertow.server.Connectors.executeRootHandler(Connectors.java:202) at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:793) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) 

Code 13 line:

  private static ResourceBundle bundle = ResourceBundle.getBundle("rts.data.databaseHelper"); 

39 line code

 dbHelper = new DatabaseHelper(); 
  • в консольном окне получаю ошибки : ... something is missing here - default locale
  • In any case, if the error is NoClassDefFoundError then most likely the code is not necessary. It is necessary to specify: 1) complete error information, 2) which class was not found, 3) where this class is located and why you consider it available. - default locale
  • @defaultlocale oops., not added. - TheSusanin
  • Clean the question from unnecessary information ( LoginView is not mentioned anywhere in the error, as well as the DBMS). Specify on which line the exception occurs ( rts.data.DatabaseHelper.<clinit>(DatabaseHelper.java:13) ) - default locale
  • No, it is better to leave the stack trace by mistake completely, it is useful. - default locale

1 answer 1

Check the following:

  1. The databaseHelper.properties file should be in the /src/main/resources/rts/data folder, not src/main/java . The java directory is for source code.
  2. Ensure that databaseHelper.properties enters the WAR file as a result of the build.
  3. Try at least for the time of debugging to make the bundle non-static and transfer the initialization to the constructor:

     private ResourceBundle bundle; public DatabaseHelper() { bundle = ResourceBundle.getBundle("rts.data.databaseHelper"); initConnectionPool(); } 

so, errors during bundle initialization will not affect the initialization of the class and the root exception will get into the logs (if it occurs)

  • did as described above. Now I have another exception. Null Pointer Exception - TheSusanin
  • @Ulukmyrza did not notice that the bundle used in initConnectionPool . See the updated DatabaseHelper constructor - default locale