db connection

Hai,My question is, how to establish a database connection from a JSP page?
[89 byte] By [nair1980a] at [2007-10-1 2:16:05]
# 1
What database are u using ?
amith_pja at 2007-7-8 11:24:47 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
oracle
nair1980a at 2007-7-8 11:24:47 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
Depends on which way you want to do...1. Load the driver class with Class.forName("...") and get Connection from that using DriverManager.2. Configure a DataSource and perform a JNDI lookup the data source to get Connection.> Carol.
hermionea at 2007-7-8 11:24:48 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

Try this ....

<%@ page import="java.sql.*" %>

<%

try{

DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:bidla2","a","b");

String Query1 = "SELECT F_NAME FROM USERS";

PreparedStatement stmt = conn.prepareStatement(Query1);

ResultSet rs = stmt.executeQuery();

while(rs.next()){

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

}

rs.close();

conn.close();

}

catch(Exception e){

}

%>

For more information, visit the following sites:

http://www.oracle.com/technology/sample_code/tech/java/sqlj_jdbc/htdocs/templates.htm

http://www.orafaq.com/faqjdbc.htm

amith_pja at 2007-7-8 11:24:48 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...