how do i conect JSP to a database?

Discussion in 'Programming' started by pedrotuga, Jun 1, 2006.

  1. #1
    i need to connect .jsp files to a database, a postgresql on to be precise...
    wich packages do i need to import?
     
    pedrotuga, Jun 1, 2006 IP
  2. acplus

    acplus Guest

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You'll need to install a driver to do this. The PostgreSQL website will most likely provide information on doing this.

    Best to look on Google, it's likely to be in a tutorial.

    Regards,
    acplus
     
    acplus, Jun 2, 2006 IP
  3. pedrotuga

    pedrotuga Peon

    Messages:
    162
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    No ofense but "use google" is not so much of a help.

    The question was objective: "which packages do i need to import"

    anyway... no JSP is being used anymore... the wole thing will be only php... anyway... if somebody can answer this i would still like to know
     
    pedrotuga, Jun 2, 2006 IP
  4. acplus

    acplus Guest

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    It's nice when people are polite.......didn't see one thank you or please!

    If your using PHP with PostgreSQL you'll need PHP compiled with PostgreSQL support enabled.

    Search for "PostgreSQL Functions" on the PHP website.

    You can then use pg_connect to connect to the database and then pg_close to close the database connection. You should find the following PHP code helpful.

    <?php
      $conn = pg_connect("dbname=mydatabase");
      if ($conn)
      {
        echo "<p>Connection successful</p>";
        pg_close($conn);
      }
      else
      {
        echo "<p>Connection unsuccessful</p>";
      }
    ?>
    Code (markup):
    PHP is a good solution but JSP is faster as it creates binaries and JSP on Linux is multithreaded. JSP provides numerous advantages over PHP and ASP. Its worth looking up.

    Regards,
    acplus
     
    acplus, Jun 4, 2006 IP