Home > Back-end >  Tomcat server runtime null pointer exception
Tomcat server runtime null pointer exception

Time:10-26

I write book city project, according to the method of teacher written JDBCUtils tools after class in the local utility class test no problem, when in running on the server to use a registered function calls JDBCUtils tool class always null pointer exception, troublesome everybody bosses to look at is how to return a responsibility?

Below is the code:
 
Public class JdbcUtils {

Private static DruidDataSource dataSource.
The static {
Try {
InputStream is=this. GetSystemClassLoader (.) getResourceAsStream (" JDBC. Properties ");
The Properties Properties=new Properties ();
The properties, the load (is);
The dataSource=(DruidDataSource) DruidDataSourceFactory. CreateDataSource (properties);
} the catch (Exception e) {
e.printStackTrace();
}
}

/* *
* access to the database connection pool connection
* @ return if return null for failure
*/
Public static Connection getConnection () {
Connection conn=null;
Try {
Conn=dataSource. GetConnection ();
} the catch (SQLException e) {
e.printStackTrace();
}
return conn;
}

/*
Close the connection, put back to the database connection pool
*/
Public static void close (Connection conn) {
If (conn!=null) {
Try {
Conn. Close ();
} the catch (SQLException e) {
e.printStackTrace();
}
}
}
}


Exceptions are as follows:
 
Java. Lang. NullPointerException
At Java. Util. The Properties of $LineReader. ReadLine (434). The Properties of Java:
The at Java. Util. Properties. Load0 (353). The Properties of Java:
The at Java. Util. Properties. The load (341). The Properties of Java:
At com. The ply. Utils. JdbcUtils. & lt; Clinit> (JdbcUtils. Java: 23)
At com. The ply. Dao. Impl. BaseDao. QueryForOne (43) BaseDao. Java:
At com. The ply. Dao. Impl. UserDaoImpl. QueryUserByUsername (UserDaoImpl. Java: 10)
At com. The ply. Service. Impl. UserServiceImpl. ExistsUsername (UserServiceImpl. Java: 28)
At com. The ply. Web. RegistServlet. DoPost (28) RegistServlet. Java:
The at javax.mail. Servlet. HTTP. HttpServlet. Service (HttpServlet. Java: 652)
The at javax.mail. Servlet. HTTP. HttpServlet. Service (HttpServlet. Java: 733)
The at org. Apache. Catalina. Core. ApplicationFilterChain. InternalDoFilter (ApplicationFilterChain. Java: 231)
The at org. Apache. Catalina. Core. ApplicationFilterChain. DoFilter (ApplicationFilterChain. Java: 166)
At org, apache tomcat, websocket server WsFilter. DoFilter (WsFilter. Java: 52)
The at org. Apache. Catalina. Core. ApplicationFilterChain. InternalDoFilter (ApplicationFilterChain. Java: 193)
The at org. Apache. Catalina. Core. ApplicationFilterChain. DoFilter (ApplicationFilterChain. Java: 166)
The at org. Apache. Catalina. Core. StandardWrapperValve. Invoke (StandardWrapperValve. Java: 199)
The at org. Apache. Catalina. Core. StandardContextValve. Invoke (StandardContextValve. Java: 96)
The at org. Apache. Catalina. The authenticator. AuthenticatorBase. Invoke (AuthenticatorBase. Java: 543)
The at org. Apache. Catalina. Core. StandardHostValve. Invoke (StandardHostValve. Java: 139)
The at org. Apache. Catalina. Valves. ErrorReportValve. Invoke (ErrorReportValve. Java: 81)
The at org. Apache. Catalina. Valves. AbstractAccessLogValve. Invoke (AbstractAccessLogValve. Java: 690)
The at org. Apache. Catalina. Core. StandardEngineValve. Invoke (StandardEngineValve. Java: 87)
At org. Apache. Catalina. Connector. CoyoteAdapter. Service (343) CoyoteAdapter. Java:
At org. Apache. Coyote. Http11. Http11Processor. Service (615) Http11Processor. Java:
The at org. Apache. Coyote. AbstractProcessorLight. Process (AbstractProcessorLight. Java: 65)
The at org. Apache. Coyote. AbstractProtocol $ConnectionHandler. Process (AbstractProtocol. Java: 818)
At org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun NioEndpoint. Java: (1626)
The at org.apache.tomcat.util.net.SocketProcessorBase.run (SocketProcessorBase. Java: 49)
The at Java. Util. Concurrent. ThreadPoolExecutor. RunWorker (ThreadPoolExecutor. Java: 1149)
The at Java. Util. Concurrent. ThreadPoolExecutor $Worker. The run (ThreadPoolExecutor. Java: 624)
At org, apache tomcat. Util. Threads. TaskThread $WrappingRunnable. Run (61) TaskThread. Java:
The at Java. Lang. Thread. The run (Thread. Java: 748)


At com. The ply. Utils. JdbcUtils. & lt; Clinit> (JdbcUtils. Java: 23) the line I think out is my code properties. The load (is); This sentence has a problem, my package directory below:

CodePudding user response:

There should be no find file, you in what way (maven build/eclipse export) playing war package? Try the files under the SRC

CodePudding user response:

JDBC can have a try in your configuration file. The properties with the following content,

TimeBetweenEvictionRunsMillis=600
InitialSize=50
MaxActive=100
MaxWait=3000

This problem should be not from the connection pool to get to the connecting lead to the controller, the service, dao is a problem,

CodePudding user response:

1, into the classes directory, see if the configuration file
2, use Telnet command to see IP port impassability
3, try to use absolute paths loading configuration files, and look at the code:
 
/* *
* get the project classpath root directory
*
* @ return String
*/
Public static String classpath () {
Try {
Return the Class. Class.forname (View. Class. GetName ()). The getResource ("/"). GetPath ();//grab a custom class to class will do
} the catch (Exception e) {
The error (e + "", e);
Throw new RuntimeException (e + "");
}
}

InputStream is=new FileInputStream (new File (the classpath () + "/JDBC. Properties"));
In this writing try
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related