Well the above methods work but those r only for testing . U shall have to write lots of silly codes in every JSP page u create to interact with database. Further they will slow down ur application, will not support high hit rates, and a lot of other problems for a real life application.
The industry standard is to create a Database Connection Pool (DBCP). For Tomcat, u shall find the methods to create DBCP, in Tomcat manual. U must also have knowledge of JNDI (Java Name and directory Interface). Beautiful manuals for all these r available at Sun web site. The J2ee manual also discusses them beautifully.
I use DBCP to connect to MySql database in Unix. If ur requirements r the same then mail me, I shall help u. But it's quite a vast topic, u shall have to read carefully the manuals I send u.
2006-10-05 08:01:03
·
answer #1
·
answered by binaryFusion 5
·
0⤊
0⤋
Below articles summarizes different ways to access DB from jsp
http://www-128.ibm.com/developerworks/java/library/j-webdata/
2006-10-04 07:18:52
·
answer #2
·
answered by okletmeanswer 2
·
0⤊
0⤋
This code is designed for Oracle, if you are not using oracle, you need to modify it a little.
<%@page contentType="text/html; charset=GBK"%>
<%@page import="java.sql.*,java.io.*,java.text.*,java.util.*,custom.Myfmt" %>
<%
String driver = application.getInitParameter("jdbc.driver");
String url = application.getInitParameter("jdbc.url");
String usr = application.getInitParameter("usr");
String ps = application.getInitParameter("passwd");
//DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
Class.forName(driver);
Connection conn = DriverManager.getConnection (url, usr, ps);
Statement stmt = conn.createStatement ();
Good Luck
2006-10-04 06:52:43
·
answer #3
·
answered by gilberts55 3
·
0⤊
0⤋
<%@ page import="java.sql.*"%>
<%
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:dsn[data source name]","[username]","[password]");
Statement stm = con.createStatement();
//now by using stm.execute([sql statement goes here]);
}catch(Exception e){}
%>
try with necessary modifications..
good luck.
2006-10-04 18:26:21
·
answer #4
·
answered by Anand 3
·
0⤊
0⤋