U K,

"It works" as you said, but there are a couple of things I'll recommend:

First, you should move your Connection, ResultSet and Statement declarations before
the try {} block and add a finally {} block where you check for null values and close
the resources if not null.


Connection conn = null;
Statement stmt = null;
ResultSet res = null;
try {
......
}
catch {
....
}
finally {
if (stmt != null ) {
try {
stmnt.close();
}
catch (SQLException se) {
log.error(se.getMessage);
}
}
....
Second, you should use a connection pool. I don't have a Tomcat config readily
available. But can follow up with one if you need it.


-Robert

U K Laxmi wrote:

I tried without GlobalNamingResources. No luck. When
googled, i found that if we include
GlobalNamingResource tag, then it will be available in
all web context.


After spending enough time on that, now i coded all
database related stuff in JSP in the way we do in
stand alone application. I mean -


Coding like this in jspo itself.

---- code --
<%@ page contentType="text/html" import="java.sql.*"%>

<html>

<head><title>simmPlan - simple material planning
system</title>
<script language="JavaScript"
src="/js/default.js"></script>

<%

 String userid = request.getParameter("userid");
 String passwd = request.getParameter("passwd");
 System.out.println("Password: " + passwd);
 String pwd = "", str = "";
 int level = -1, ind = -1;

try {
Connection conn = null;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

conn=DriverManager.getConnection("jdbc:odbc:driver={Microsoft
Access Driver
(*.mdb)};DBQ=C:/tomcat/webapps/db1/db1.mdb");
Statement stmt =
conn.createStatement();
String query = "SELECT * FROM user
where name = '" + userid + "'";
ResultSet st =
stmt.executeQuery(query);
if (st.next()) { pwd = st.getString("password"); level = st.getInt("level");
System.err.println("Query
result="+userid+"/"+pwd+"/"+level);
}
else {
ind = -2;
System.out.println("No user with name " + userid
+ " available in the database");
}


               if (stmt != null) {
                   stmt.close();
               }

if (conn != null) {
conn.close();
}
} catch (Exception e) {
e.printStackTrace();
} if(pwd.equals(passwd)) {
ind = level;
}
// else ind = -1;


                                 System.out.println("Ind - > " + ind);
%>

<script language="JavaScript" type="text/JavaScript">
var ind = <%= ind %>

function loadHtml() {
        //alert("in loadHtml()");
        if(ind == -2) {
                alert("Not a valid user");
                location.href = "login.jsp";
                return;
        }
        if (ind == -1) {
                alert("Incorrect password");
                location.href = "login.jsp";
                return;
        }
        else {
                //alert("Correct password");
                location.href = "Second_Page.html";
                return;
        }
}


</script> </head>

<body onload="javascript:loadHtml()">

<!-- User Name : <%= userid %><br>
Password  : <%= passwd %> -->

</body>

</html>
--- code ends here ---

It works. But is it the right way to do? Pls advice.

--- Antony Paul <[EMAIL PROTECTED]> wrote:



By default server.xml contains have a <GlobalNamingResources>. You
have to add your resources in there.


rgds
Antony Paul


On Mon, 21 Feb 2005 19:56:23 -0800 (PST), U K Laxmi
<[EMAIL PROTECTED]> wrote:


As just moved the GlobalNamingResources inside the
main <server> in my server.xml residing in
TOMCAT_HOME/conf directory. When i restart tomcat
5.5.7 it's throwing up following exception.
INFO: Starting Servlet Engine: Apache Tomcat/5.5.7
Feb 22, 2005 11:51:46 AM
org.apache.catalina.realm.UserDatabaseRealm start
SEVERE: Exception looking up UserDatabase under


key


UserDatabase
javax.naming.NameNotFoundException: Name


UserDatabase


is not bound in this Conte
xt
       at



org.apache.naming.NamingContext.lookup(NamingContext.java:769)


       at



org.apache.naming.NamingContext.lookup(NamingContext.java:152)


       at



org.apache.catalina.realm.UserDatabaseRealm.start(UserDatabaseRealm.j


ava:222)
       at



org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1003)


       at



org.apache.catalina.core.StandardEngine.start(StandardEngine.java:440


)
       at



org.apache.catalina.core.StandardService.start(StandardService.java:4


50)
       at



org.apache.catalina.core.StandardServer.start(StandardServer.java:683


)
       at



org.apache.catalina.startup.Catalina.start(Catalina.java:537)


       at



sun.reflect.NativeMethodAccessorImpl.invoke0(Native


Method)
       at



sun.reflect.NativeMethodAccessorImpl.invoke(Unknown


Source)
       at



sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown


Source)
       at java.lang.reflect.Method.invoke(Unknown
Source)
       at



org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:271)


       at



org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:409)


Feb 22, 2005 11:51:46 AM
org.apache.catalina.startup.Catalina start
SEVERE: Catalina.start:
LifecycleException: No UserDatabase component


found


under key UserDatabase
       at



org.apache.catalina.realm.UserDatabaseRealm.start(UserDatabaseRealm.j


ava:228)
       at



org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1003)


       at



org.apache.catalina.core.StandardEngine.start(StandardEngine.java:440


)
       at



org.apache.catalina.core.StandardService.start(StandardService.java:4


50)
       at



org.apache.catalina.core.StandardServer.start(StandardServer.java:683


)
       at



org.apache.catalina.startup.Catalina.start(Catalina.java:537)


       at



sun.reflect.NativeMethodAccessorImpl.invoke0(Native


Method)
       at



sun.reflect.NativeMethodAccessorImpl.invoke(Unknown


Source)
       at



sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown


Source)
       at java.lang.reflect.Method.invoke(Unknown
Source)
       at



org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:271)


       at



org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:409)


Feb 22, 2005 11:51:46 AM
org.apache.catalina.startup.Catalina start
INFO: Server startup in 391 ms

Pls help to fix the problem.

Thanks,
Laxmi

--- Antony Paul <[EMAIL PROTECTED]> wrote:



It seems you still have problem. You can google


for


the answer. One
thing I know is GlobalNamingResources should


come


inside the Server
element and not inside Context element.

rgds
Antony Paul


On Fri, 18 Feb 2005 22:47:06 -0800 (PST), U K


Laxmi


<[EMAIL PROTECTED]> wrote:


I could able to get thro' JarperException.


Thanks


for


replies.

Now facing new problem.

I'm getting "NameNotFoundException" - Name


jdbc


is


not bound in this Context

Environment what i'm using is: Apache 2,


Tomcat


5.5,


Netscape 7.2, MsAccess 2003 on windows 2000


machine.


I integrated tomcat and apache as apache


doesn't


support jsps. I wrote a JSP called test-db.jsp


which


in turn calls java program TestSQLLoad.java.


This


TestSQLLoad.java performs dattabase operation,


fetches


the data from table and that data is displayed


on


Netscape thro' jsp.

1. test-db.jsp resides ina directory
TOMCAT_HOME/webapps/web/JSP. Contents are as


follows:


<%@ page contentType="text/html"
import="testpkg.TestSQLLoad"%>

       <html>
     <head>
       <title>DB Test</title>
     </head>
     <body>

     <%
       TestSQLLoad tst = new TestSQLLoad();
       tst.init();
     %>

     <h2>Results</h2>
       User -> <%= tst.getUser() %><br/>
       Pwd -> <%= tst.getPassword() %><br/>
       Id -> <%= tst.getID() %>



=== message truncated ===





__________________________________ Do you Yahoo!? Yahoo! Mail - You care about security. So do we. http://promotions.yahoo.com/new_mail


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]







Reply via email to