خرید بک لینک

Vote count: 0

Hello all i am using rest and mysql as my db.

Below is my rest get code for getting allbooks(Resource)

@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getBooks(@QueryParam("format") String format) {

    return Response.status(Status.OK).entity((new GenericEntity<List<Book>>(bookService.getAllBooks()) {
    })).header(HttpHeaders.CONTENT_TYPE, "XML".equalsIgnoreCase(format)
            ? MediaType.APPLICATION_XML + ";charset=UTF-8" : MediaType.APPLICATION_JSON + ";charset=UTF-8").build();

}

Below is my service

public List<Book> getAllBooks() {

    return new ArrayList<Book>(booksDao.getAllBooks());
    /* return new ArrayList<Book>(books.values()); */
}

Below is my DB

public List<Book> getAllBooks() {
    return jdbcTemplate.query("select * from books.books_table", new RowMapper<Book>() {

        @Override
        public Book mapRow(ResultSet rs, int rownumber) throws SQLException {
            Book e = new Book();
            e.setId(rs.getInt(1));

            e.setName(rs.getString(2));

            e.setPrice(rs.getString(3));

            e.setAuthor(rs.getString(4));

            return e;
        }


    });
}

Below is my bean.I am using springJDBC

<?xml version="1.0" encoding="UTF-8"?>  
<beans  
xmlns="http://www.springframework.org/schema/beans"  
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
xmlns:p="http://www.springframework.org/schema/p"  
xsi:schemaLocation="http://www.springframework.org/schema/beans   
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">  

<bean id="ds" 
class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 
<property name="driverClassName" value="com.mysql.jdbc.Driver" />  
<property name="url" value="jdbc:mysql://localhost:3306/xxxx" />  
<property name="username" value="xxxx" />  
<property name="password" value="xxxx" />  
</bean>  

<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">  
<property name="dataSource" ref="ds"></property>  
</bean>  

<bean id="edao" class="com.nag.library.database.BooksDAO">  
<property name="jdbcTemplate" ref="jdbcTemplate"></property>  
</bean>  

</beans> 

Without coecting to db i am fine getting the json/xml response but when i coect db its throwing a nullpointer exception

Aug 16, 2016 10:43:08 AM org.apache.catalina.core.StandardWrapperValve
invoke     
SEVERE: Servlet.service() for servlet Jersey Web Application threw exception
java.lang.NullPointerException
at com.nag.library.database.BooksDAO.getAllBooks(BooksDAO.java:24)
at com.nag.library.service.BookService.getAllBooks(BookService.java:24)
at com.nag.library.resource.BookResource.getBooks(BookResource.java:35)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at java.lang.Thread.run(Unknown Source)

Where i'm doing the thing wrong.Please guide me.

Thank you

asked 50 secs ago

برچسب: getting null pointer exception java,getting null pointer exception in selenium webdriver,getting null pointer exception in junit test,getting null pointer exception,map get null pointer exception, نویسنده: استخدام کار تاريخ: چهارشنبه 27 مرداد 1395 ساعت: 2:01

صفحه بندی