samedi 8 décembre 2018

JDBC Web application in netbeans with wildfly server

I am trying to run my Web application in netbeans with wildfly server. I got error

"jboss.naming.context.java.module.LocalShop.LocalShop.env.ReadBean.dp is missing [jboss.naming.context.java.jboss.datasources.shopstyles]" and I think line @Resource (lookup= "java:jboss/datasources/shopstyles") is causing the error. Can someone help me?

Package structure MANIFEST.MF

My code for web application in netbeans:

import java.io.Serializable;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
import javax.sql.DataSource;

@Named (value="readBean")
@RequestScoped
public class ReadBean implements Serializable {
  @Resource (lookup= "java:jboss/datasources/shopstyles")
    private DataSource dp;

    public List<Veggie>performRead() throws SQLException{
         if(dp == null){
            throw new SQLException("Cannot access data pool");
        }
         List<Veggie>list;
        try (Connection con =dp.getConnection()){
            if(con == null){
                throw new SQLException("Cannot establish connection to database");
            }
            PreparedStatement ps =con.prepareStatement("select veggie_id,name,price,created_date from veggie");
            ResultSet result =ps.executeQuery();
            list=new ArrayList<>();
            while(result.next()){
          Veggie veggie=new Veggie();
          veggie.setVeggieID(result.getInt("veggie_id"));
           veggie.setName(result.getString("name"));
           veggie.setPrice(result.getString("price"));
           veggie.setCreated_date(result.getDate("created_date"));
            list.add(veggie);


            }


    }
        return list;
    }



}

Manifest.mf code:

Manifest-Version: 1.0




Aucun commentaire:

Enregistrer un commentaire