June 27, 2012

Adding an EJB to a web application in netbeans

Question by henry joseph

I was following a tutorial on how to create a web application in netbeans using Java EE 6. The tutor added a new bean by just right clicking on the project name->new->session bean. When I tried to follow the same instruction, I didn’t find the session bean when I went to new. I am using netbeans 6.9.1. Is there a way to add it ?

Thanks

Answer by Starx

You can add, the session beans, by using project pane on the left side. (If this is not showing, Press Ctrl + 1 or go to windows -> select Projects)

Then to add the session beans

  • Right your project
  • Go to New
  • Find Session Beans, If not go to others
  • There find a category called “Enterprise JavaBeans”
  • Select Session Bean
  • Continue and complete the wizard.
April 13, 2011

php function returning a string with a new line?

Question by Jorge

In my first 3 days in coding my homework. I successfully did it. But when I got to school, my code have a problem. I have an ajax form and some php functions.

Here is an example.

$i = 1
if($i == 1) {
   echo "yes";
}
else {
   echo "no";
}

The answer in my sample is true. But in my case it’s always false. And I notice the ajax requests that the returned message was

    // new line
    // new line
yes
    // new line

That’s why it’s being false. What is the cause of this? I didn’t put any new line in my code.

Answer by Starx

If you want the easy way out of it, try this

ob_clean();
echo "yes";
exit;
May 17, 2010

output all data from db to a php page

Question by Sarit

I’m a real beginner with PHP & mysql.
Just for studying and for a simple example at school I would like to work this simple query and possibly output all the rows (or maybe even one) to a very basic output on a php page:

<?php
$user= "root";
$host="localhost";
$password="";
$database = "PetCatalog";
$cxn = mysqli_connect($host,$user,$password,$database)
or die ("couldn’t connect to server");
$query = "SELECT * FROM Pet";
$result = mysql_query($cxn,$query) or die ("Couldn’t execute query.");
$row = mysqli_fetch_assoc($result);
echo "$result";
?>

this is the error message i’ve been getting:

Warning: mysql_query() expects parameter 1 to be string, object given in C:xampplitehtdocsmyblogquery.php on line 18
Couldn’t execute query.

What should I do?
Thanks!

Answer by Starx

<?php
$user= "root";
$host="localhost";
$password="";
$database = "PetCatalog";
$cxn = mysqli_connect($host,$user,$password,$database)
or die ("couldn’t connect to server");
$query = "SELECT * FROM Pet";
$result = mysql_query($query) or die ("Couldn’t execute query.");
while($row = mysqli_fetch_array($result)) {
          print_r($row);
}
?>

This should solve your problem

...

Please fill the form - I will response as fast as I can!