Good for testing, however in a real system you really should consider using a connection pool of some type. I personally use poolman whenever I need a database connection, so using their little test webapp is nice (and it'll allow me to check things on production which is also nice).
--mikej -=----- mike jackson [EMAIL PROTECTED] > -----Original Message----- > From: Kenny G. Dubuisson, Jr. [mailto:[EMAIL PROTECTED]] > Sent: Tuesday, February 11, 2003 11:13 AM > To: Tomcat Users List > Subject: Re: TOMCAT versus ORACLE > > > Here is a little servlet I threw together for you. You will have > to change > the variable "url" to fit your database connection string and the > "password" > variable. Besides that, it should work for you. Let me know what the > output is and I'll try to help if it doesn't work. Thanks, > Kenny > > import java.io.*; > import java.sql.*; > import javax.servlet.*; > import javax.servlet.http.*; > > public class OracleTest extends HttpServlet > { > public void doGet(HttpServletRequest request, HttpServletResponse > response) > throws ServletException, IOException > { > // Initialize variables. > Connection myConnection = null; > Statement myStatement = null; > String url = "jdbc:oracle:thin:@oracle:1521:oracle"; > String username = "system"; > String password = "xxxxxx"; > ResultSet myResultSet = null; > > // Set up output. > response.setContentType("text/html"); > PrintWriter out = response.getWriter(); > > try > { > // Load (and therefore register) the Oracle Driver. > Class.forName("oracle.jdbc.driver.OracleDriver"); > > // Get a connection to the database. > myConnection = DriverManager.getConnection(url, username, > password); > > // Create a statement object. > myStatement = myConnection.createStatement(); > > // Execute a SQL query...get a result set. > String sql = "SELECT * FROM DBA_USERS"; > myResultSet = myStatement.executeQuery(sql); > > // Output HTML header. > out.println("<html><body>"); > > if (myResultSet.next()) > { > // Result good. > out.println("IT WORKED!"); > } > else > { > // Result bad. > out.println("IT FAILED!"); > } > > // Output HTML footer. > out.println("</BODY></HTML>"); > } > catch (ClassNotFoundException cnfe) > { > // Output exception. > out.println("Couldn't load database driver: " + > cnfe.getMessage()); > } > catch (SQLException sqle) > { > // Output exception. > out.println("SQLException caught: " + sqle.getMessage()); > } > } > } > > > > *********************************************************************** > > > > Yes, it is! I correct is not TOMCAT versus ORACLE, but TOMCAT > with ORACLE > > > > -----Original Message----- > > From: Kenny G. Dubuisson, Jr. [mailto:[EMAIL PROTECTED]] > > Sent: ter�a-feira, 11 de Fevereiro de 2003 18:43 > > To: Tomcat Users List > > Subject: Re: TOMCAT versus ORACLE > > > > Not sure what you mean by "versus". If you want an example to test a > oracle > > connection through a JSP or servlet via the Tomcat engine, let me know. > > Kenny > > > > ----- Original Message ----- > > From: "Alberto A C A S Magalh�es" <[EMAIL PROTECTED]> > > To: "Tomcat Users List" <[EMAIL PROTECTED]> > > Sent: Tuesday, February 11, 2003 12:37 PM > > Subject: TOMCAT versus ORACLE > > > > > > ********************************************************************** > > Este email assim como os ficheiros que possa ter em anexo s�o > confidenciais > > e para uso exclusivo da pessoa ou organiza��o para o qual foi enviado. > > Se recebeu este email por engano por favor notifique [EMAIL PROTECTED] > > > > Esta nota confirma que esta mensagem foi verificada pelo MIMEsweeper > > n�o tendo sido encontrados virus. > > > > www.mimesweeper.com > > *********************************************************************** > > > > Hi, > > Anyone knows if exists a quick example to test if the connection TOMCAT > > versus ORACLE is working? > > > > Thanks > > Alberto Magalh�es. > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
