Home > Back-end >  Database connection pool why null pointer exception
Database connection pool why null pointer exception

Time:09-23



String SQL="select * from the user where the username=? And password=?" ;
User User=template. QueryForObject (SQL, new BeanPropertyRowMapper (the User. The class), loginUser. GetUsername (), loginUser. GetPassword ());

Don't understand BeanPropertyRowMapper The role of (User. The class),

CodePudding user response:

BeanPropertyRowMapper (User. The class), you can understand as a data model,
Will you this SQL to check the data according to your rules of the User data model, encapsulated into a User object
So you this queryForObject method return value type is a User

Null pointer problem is that the query returns null may not necessarily the returned result is an empty line (you can as a small bug),
Solution can be: direct try-catch the query if thrown null pointer directly to the user assignment to null
Is whether the query to the empty rows of data or no data, the final result is null

CodePudding user response:

Find out problems, thought is JDBCUtils tools for DateSource assignment problems, when creating the template into the DataSource, lead to the template while creating, but can not connect to the database correctly,

CodePudding user response:

I also am null pointer exception difficult oh play on me

CodePudding user response:

See if it's all right to connect to the database
  • Related