public void insert(Player player) throws NamingException
    {

        
        String INSERT_STMT="insert into player(name,address,city,province,postal_code) values(?,?,?,?,?)";       // JDBC variables
       
        DataSource ds = null;
        Connection connection = null;
        PreparedStatement insert_stmt = null;
      
        
         try {

            // Retrieve the DataSource from JNDI
            Context ctx = new InitialContext();
            if (ctx == null) {
                throw new RuntimeException("JNDI Context could not be found.");
            }
            ds = (DataSource) ctx.lookup("jdbc/myDatasource");
            
            if (ds == null) {
                throw new RuntimeException("DataSource could not be found.");
            }

            // Get a database connection
            connection = ds.getConnection("root","btes");

            // Create SQL INSERT statement
            insert_stmt = connection.prepareStatement(INSERT_STMT,Statement.RETURN_GENERATED_KEYS);
            
            insert_stmt.setString(1,player.getName());
            insert_stmt.setString(2,player.getAddress());
            insert_stmt.setString(3,player.getCity());
            insert_stmt.setString(4,player.getProvince());
            insert_stmt.setString(5,player.getPostalcode());
            
            int id  = insert_stmt.executeUpdate(); 
            ResultSet generatedKeys = insert_stmt.getGeneratedKeys();
              if (generatedKeys.next()) {
            player.setPID(generatedKeys.getInt(1));
            System.out.println("player id--"+player.getPID());
        } else {
            throw new SQLException("Creating user failed, no generated key obtained.");
        }
            
           
             
            
            
           
            // Get the next Player object ID
            
    }catch (SQLException e) {
            throw new RuntimeException("A database error occured. "
                    + e.getMessage());

            // Handle any JNDI errors
        } catch (NamingException e) {
            throw new RuntimeException("A JNDI error occured. " + e.getMessage());

            // Clean up JDBC resources
        } finally {
            if (insert_stmt != null) {
                try {
                    insert_stmt.close();
                } catch (SQLException e) {
                }
            }
            if (connection != null) {
                try {
                    connection.close();
                } catch (Exception e) {
                    e.printStackTrace(System.err);
                }
            }
        }
    }