You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Mario Henley Becerril Geldis <he...@uaemex.mx> on 2002/07/22 17:21:45 UTC

Run class on jsp


  I am a beginner on JSP enviroment..

  I have a class file, this connect a Oracle database, and query to single
table...now i want run this class on a jsp page...how i do it..??

  my code:

  import java.sql.*; 

import java.io.*; 

import java.util.Date; 

class JdbcTest

{ 

  public static void main (String args []) 

      throws SQLException, IOException

  { 
    System.out.println ("Loading Oracle driver"); 

    try 

    {

      Class.forName ("oracle.jdbc.driver.OracleDriver");
      
    } 

    catch (/*ClassNotFound*/ Exception e) 

    {

      System.out.println ("Could not load the driver"); 

      e.printStackTrace (); 

     }

    System.out.println ("Connecting to the remote database"); 

     Connection conn = DriverManager.getConnection
("jdbc:oracle:thin:@(DESCRIPT
ION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.3.4)(PORT =
1521)
))(CONNECT_DATA =(SERVICE_NAME = votoedos)(SRVR =
DEDICATED)))","scott","enie");

    System.out.println ("OK");
    Statement stmt = conn.createStatement (); 

    // Query the employee names 
    
    ResultSet rset = stmt.executeQuery ("SELECT dttofed From
TDFDF97_NL");
    
    while (rset.next ()) 
      
      { 

        // Print the name out 

        System.out.println (rset.getString (1)); 

      } 
  } 
  
} 


  



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Run class on jsp

Posted by Brad Rhoads <br...@zethcon.com>.
This is probably a better question to ask at Sun's JSP-INTEREST list.

But here's a quick example to get you started.

<jsp:useBean id="dDBInterface" scope="session"
class="com.zethcon.WebSynapse.DBInterface" />

. . .

<%
  String sUserName 	= ((String)session.getValue("PID"));
  String sVPath = "";

   if(dDBInterface.insertWebTransLog(sUserName,sVPath +
"websynapse/OrderInq/InBoundDtl.jsp"))
   {}

 %>

-----Original Message-----
From: Mario Henley Becerril Geldis [mailto:henley@uaemex.mx]
Sent: Monday, July 22, 2002 10:22 AM
To: tomcat-user@jakarta.apache.org
Subject: Run class on jsp




  I am a beginner on JSP enviroment..

  I have a class file, this connect a Oracle database, and query to single
table...now i want run this class on a jsp page...how i do it..??

  my code:

  import java.sql.*;

import java.io.*;

import java.util.Date;

class JdbcTest

{

  public static void main (String args [])

      throws SQLException, IOException

  {
    System.out.println ("Loading Oracle driver");

    try

    {

      Class.forName ("oracle.jdbc.driver.OracleDriver");

    }

    catch (/*ClassNotFound*/ Exception e)

    {

      System.out.println ("Could not load the driver");

      e.printStackTrace ();

     }

    System.out.println ("Connecting to the remote database");

     Connection conn = DriverManager.getConnection
("jdbc:oracle:thin:@(DESCRIPT
ION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.3.4)(PORT =
1521)
))(CONNECT_DATA =(SERVICE_NAME = votoedos)(SRVR =
DEDICATED)))","scott","enie");

    System.out.println ("OK");
    Statement stmt = conn.createStatement ();

    // Query the employee names

    ResultSet rset = stmt.executeQuery ("SELECT dttofed From
TDFDF97_NL");

    while (rset.next ())

      {

        // Print the name out

        System.out.println (rset.getString (1));

      }
  }

}






--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>