Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Help coderanch get a
new server
by contributing to the fundraiser

Adam Dear

Greenhorn
+ Follow
since Oct 21, 2003
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Adam Dear

I am trying to create a microsoft SQL Server 2000 datasource on Tomcat 5.5.12. I have read the documentation on the Apache Tomcat website on how to do it, but I can't seem to get it to work.

Here is what I have done.

1. I have put the sql server jdbc driver in c:\tomcat\common\lib.
2. Added
<Resource name="jdbc/cimmarron_com" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000" username="usr" password="xxxx"
driverClassName="com.microsoft.jdbc.sqlserver.SQLServerDriver"
url="jdbc:microsoft:sqlserver://192.168.1.2?user=xxx;password=xxx;database=xxx"/>
to my server.xml file. I also tried adding it to myApp.xml under tomcat\conf\Cataline\host
3. I added
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/cimarron_com</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
to the web.xml file under my application WEB-INF directory

I am trying to use the datasource in a .jsp page. When I load the page, I am getting a message that says:
"Unable to get connection, DataSource invalid: "org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'"

I have read several topcis here and else where, but I can't seem to track down the problem.
Here are the full contents of server.xml, web.xml, the .jsp I am using, and the myApp.xml file which contains the same context element as the server.xml

server.xml
===========
<Server port="8080" shutdown="SHUTDOWN">

<Listener className="org.apache.catalina.core.AprLifecycleListener" />
<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.storeconfig.StoreConfigLifecycleListener"/>

<!-- Global JNDI resources -->
<GlobalNamingResources>

<!-- Test entry for demonstration purposes -->
<Environment name="simpleValue" type="java.lang.Integer" value="30"/>

<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users -->
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />

</GlobalNamingResources>


<!-- Define the Tomcat Stand-Alone Service -->
<Service name="Catalina">



<!-- Define a non-SSL HTTP/1.1 Connector on port 8080 -->
<Connector
port="8000" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true" />
<!-- Note : To disable connection timeouts, set connectionTimeout value
to 0 -->

<!-- Note : To use gzip compression you could set the following properties :

compression="on"
compressionMinSize="2048"
noCompressionUserAgents="gozilla, traviata"
compressableMimeType="text/html,text/xml"
-->

<!-- Define a SSL HTTP/1.1 Connector on port 8443 -->
<!--
<Connector port="8443" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" disableUploadTimeout="true"
acceptCount="100" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" />
-->

<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009"
enableLookups="false" redirectPort="8443" protocol="AJP/1.3" />

<!-- Define a Proxied HTTP/1.1 Connector on port 8082 -->
<!-- See proxy documentation for more information about using this. -->
<!--
<Connector port="8082"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" acceptCount="100" connectionTimeout="20000"
proxyPort="80" disableUploadTimeout="true" />
-->

<!-- You should set jvmRoute to support load-balancing via AJP ie :
<Engine name="Standalone" defaultHost="localhost" jvmRoute="jvm1">
-->

<!-- Define the top level container in our container hierarchy -->
<Engine name="Catalina" defaultHost="localhost">

<!--
<Valve className="org.apache.catalina.valves.RequestDumperValve"/>
-->

<!-- Because this Realm is here, an instance will be shared globally -->

<!-- This Realm uses the UserDatabase configured in the global JNDI
resources under the key "UserDatabase". Any edits
that are performed against this UserDatabase are immediately
available for use by the Realm. -->
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>

<!-- Comment out the old realm but leave here for now in case we
need to go back quickly -->
<!--
<Realm className="org.apache.catalina.realm.MemoryRealm" />
-->

<!-- Replace the above Realm with one of the following to get a Realm
stored in a database and accessed via JDBC -->

<!--
<Realm className="org.apache.catalina.realm.JDBCRealm"
driverName="org.gjt.mm.mysql.Driver"
connectionURL="jdbc:mysql://localhost/authority"
connectionName="test" connectionPassword="test"
userTable="users" userNameCol="user_name" userCredCol="user_pass"
userRoleTable="user_roles" roleNameCol="role_name" />
-->

<!--
<Realm className="org.apache.catalina.realm.JDBCRealm"
driverName="oracle.jdbc.driver.OracleDriver"
connectionURL="jdbc racle:thin:@ntserver:1521 RCL"
connectionName="scott" connectionPassword="tiger"
userTable="users" userNameCol="user_name" userCredCol="user_pass"
userRoleTable="user_roles" roleNameCol="role_name" />
-->

<!--
<Realm className="org.apache.catalina.realm.JDBCRealm"
driverName="sun.jdbc.odbc.JdbcOdbcDriver"
connectionURL="jdbc dbc:CATALINA"
userTable="users" userNameCol="user_name" userCredCol="user_pass"
userRoleTable="user_roles" roleNameCol="role_name" />
-->

<!-- Define the default virtual host
Note: XML Schema validation will not work with Xerces 2.2.
-->
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->

<!--
<Valve className="org.apache.catalina.valves.AccessLogValve"
directory="logs" prefix="localhost_access_log." suffix=".txt"
pattern="common" resolveHosts="false"/>
-->
<!--
<Valve className="org.apache.catalina.valves.FastCommonAccessLogValve"
directory="logs" prefix="localhost_access_log." suffix=".txt"
pattern="common" resolveHosts="false"/>
-->

</Host>
<Host name="adear01" unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<Context path ="/corrwebv2" docBase="c:\www\corrwebv2\" reloadable="true">
<Resource name="jdbc/cimmarron_com" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000" username="xxx" password="xxx"
driverClassName="com.microsoft.jdbc.sqlserver.SQLServerDriver"
url="jdbc:microsoft:sqlserver://192.168.1.2?user=xxx;password=xxx;database=xxx"/>
</Context>
</Host>

</Engine>

</Service>

</Server>

web.xml
========
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<servlet>
<servlet-name>TestServlet</servlet-name>
<servlet-class>coreservlets.TestServlet2</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TestServlet</servlet-name>
<url-pattern>/Test</url-pattern>
</servlet-mapping>
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/cimarron_com</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>

corrwebv2.xml
==========
<?xml version='1.0' encoding='utf-8'?>
<Context path ="/corrwebv2" docBase="c:\www\corrwebv2\" reloadable="true">
<Resource name="jdbc/cimmarron_com" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000" username="xxx" password="xxx"
driverClassName="com.microsoft.jdbc.sqlserver.SQLServerDriver"
url="jdbc:microsoft:sqlserver://192.168.1.2?user=xxx;password=xxx;database=xxx"/>
</Context>

datasourcetest.jsp
============
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<sql:query var="rs" dataSource="jdbc/cimarron_com">
select U_Email from CC_User
</sql:query>

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

<h2>Results</h2>

<c:forEach var="row" items="${rs.rows}">
Email ${row.U_Email}<br/>
</c:forEach>

</body>
</html>

Please offer any suggestions that could remedy this problem. Thanks
18 years ago
I am currently working on a small gui program for school. The assignment is to read in approximately 1000 items from 10 different files, create an instance of my name object, store all items in an array, and the sort the array. This is not part of the assignment, so I'm not asking you to do my work for me, but I would like to use a JProgress Bar to show the status of the startup process. All of the steps listed above happen before the gui is loaded.

I have read "How to Use a Progress Bar" on the java site, but it really doesn't help me. Could someone please help me to figure out how to use the progress bar. I would like to have a bar track the progress of reading all of the info from the files, and then start the progress bar over to track the progress of the sort. Here is the code where I read in the files and sort the array:

[ April 21, 2005: Message edited by: Adam Dear ]
19 years ago
I am trying to get the Advice Guy EJB from hfejb to work. I have been working on this for quite a while. i was unable to use j2ee 1.3 because for some reason the installer wouldn't work on Win XP sp2, so I am using j2ee 1.4 with the Sun Application Server. Anyone know why the installer wouldn't work?

Anyway, The problem I am having is I can't figure out how to add the jndi name as indicated in the book with the deploytool. When I am using the tool from Sun Application Server 8, it never asks what the jndi name should be. Because of this, I am getting a javax.naming.NameNotFoundException when I try to run the AdviceClient.

Can anyone help me, I am about at my wits end, and I really want to learn this, but if I can't get this to work I won't be able too.

thanks
Does anyone know where I might find a class that will convert a normal string into one that is formated for a url? What I mean is if I pass it a string:

This is a string

I want it to return:

This+is+a+string

so that I can append this to a url in an anchor tag which is generated through a servlet, bean, jsp or whatever.

Thanks
-A
19 years ago
Thanks for the help, It is working now
[ November 02, 2004: Message edited by: Adam Dear ]
19 years ago
JSP
I am trying to connect to a java bean from a .jsp, but the server is giving an HTTP Status 500 error. Can someone tell me what might be wrong.
Here is my code:

CalculatorBean:
public class CalculatorBean
{
public int doubleIt(int number)
{
return 2 * number;
}
}

SimplePage.jsp:
<jsp:useBean id="theBean" class="CalculatorBean"/>
<html>
<head>
</head>
<body>
<%
int i = 4;
int j = theBean.doubleIt(i);
out.println("2*4="+j);
%>
</body>
</html>

Here is the nasty looking error that tomcat gives:

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 1 in the jsp file: /SimplePage.jsp
Generated servlet error:
C:\Program Files\Apache Group\Tomcat 5.0\work\Catalina\localhost\myApp\org\apache\jsp\SimplePage_jsp.java:42: cannot find symbol
symbol : class CalculatorBean
location: class org.apache.jsp.SimplePage_jsp
CalculatorBean theBean = null;
^


An error occurred at line: 1 in the jsp file: /SimplePage.jsp
Generated servlet error:
C:\Program Files\Apache Group\Tomcat 5.0\work\Catalina\localhost\myApp\org\apache\jsp\SimplePage_jsp.java:44: cannot find symbol
symbol : class CalculatorBean
location: class org.apache.jsp.SimplePage_jsp
theBean = (CalculatorBean) _jspx_page_context.getAttribute("theBean", PageContext.PAGE_SCOPE);
^


An error occurred at line: 1 in the jsp file: /SimplePage.jsp
Generated servlet error:
C:\Program Files\Apache Group\Tomcat 5.0\work\Catalina\localhost\myApp\org\apache\jsp\SimplePage_jsp.java:46: cannot find symbol
symbol : class CalculatorBean
location: class org.apache.jsp.SimplePage_jsp
theBean = new CalculatorBean();
^
3 errors

Can someone offer any suggestions as to what the problem is?

Thanks-
A
19 years ago
JSP
Thanks for the suggestions. I finally got it to work by adding a <servlet-mapping> element to the application web.xml file.

thanks again!!!
19 years ago
I am trying to set up tomcat on my dev. server. I am having trouble getting my servlets to work. I have tried to follow the directions for Tomcat 5 on its site, but they are kind of confusing. I also have a servlet book, but it talks about Tomcat 4. something. Is there a big difference between 4 and 5? Anyway, when I try to view a servlet, the server gives a HTTP 404 error, and says the resource is not available.

Here is what I have done:

1. linked apache and tomcat with mod_jk2. This is working fine for jsp
2. created dir. structure tomcat\webapps\myApp\WEB-INF\classes.
3. saved and compiled servlet to classes subdirectory.
4. created web.xml descriptor in web-inf directory.
5. access the servlet at http://localhost:8000/8080/myApp/servlet/Servlet
port 8000 is the tomcat port, and 8080 is the apache port

This gives the 404 error everytime I try to access the servlet.

I am able to access the admin and management part of tomcat so I know it is working, and my .jsp pages also work, just not the servlets.

Can anyone help???
Thanks
[ October 25, 2004: Message edited by: Adam Dear ]
19 years ago
Thanks for the help. I went back and looked at my classpath, and found that I had left off the .jar extension of one of the files
Hello all,
I am trying to connect to a MS Sql Server database using the jdbc driver provided by MS. When I try to run the program, I get a ClassNotFoundException. Here is the line generating the exception:
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
I have added the three .jar files that were installed to the classpath, but still get this error.
I'm sure there is something simple that I am missing, but could someone please give me some advice. Here is the entire code for the problem:
try
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection connection = DriverManager.getConnection("jdbc:microsoft:sqlserver://myip:1433","uid","pwd");
Statement statement=connection.createStatement();

String query="select * from test.SHIPPING";
ResultSet resultSet = statement.executeQuery(query);

while(resultSet.next())
{
System.out.println("pn="+resultSet.getString(1).toString()+"sn="+resultSet.getString(2));
}
}
catch(Exception e)
{
System.out.println("Error with connection "+e.toString());
}
Please give me any advice thanks
-A
Thanks for the info. I have it working now. One other question, is there a way I can give the first cell of the new row the focus so the the user can simply type another number without having to click in the cell first?
20 years ago
I am attempting to write a program to track serial numbers of products that are sent out on sales orders. This really isn't for anyone, it is just something I came up with based on an experience I had at the place I worked while I was out of school for Christmas.
Anyway, I am trying to use a JTable to allow a user to enter a part number and a serial number in a row in two cells. As a row is populated, I need to add another blank row to the JTable. The problem is, I am not sure how to go about dynamically adding rows to a table. If a JTable is not the best way to go about this, please offer any suggestions.
As it is probably obvious, I am still trying to learn Java, and this program is nothing more than my trying to improve my understanding of the language. Please help, thanks
-A
20 years ago
Hi all,
First let me say that I am EXTREMELY new to Java and even more so Tomcat. I am writing my servlets and placing them in the proper directory. I can load them once, but after that, if I make any changes to the file, and recompile it, I must completly restart Tomcat in order to view the changes.
I quesss my question is, is there anything that can be done about this. It is very frustrating to have to restart the server everytime I change something during development.
Thanks
20 years ago