AW: Re: [opencms-dev] Addressing external database from JSP
Roleff at Laatzen.de
Roleff at Laatzen.de
Tue May 4 09:15:03 CEST 2004
That's it.
Thank's too.
-----Ursprüngliche Nachricht-----
Von: Hartmann, Waehrisch & Feykes GmbH
[mailto:hartmann at waehrisch-feykes.de]
Gesendet: Montag, 3. Mai 2004 16:47
An: opencms-dev at opencms.org
Betreff: Re: Re: [opencms-dev] Addressing external database from JSP
For a quick test try this:
static {
try {
Class.forName(sDbDrv);
}
catch (Exception e) { }
}
----- Original Message -----
From: "Björn Schlueter" <bschlueter at lenord.de>
To: <opencms-dev at opencms.org>
Sent: Monday, May 03, 2004 11:56 AM
Subject: Antw: Re: [opencms-dev] Addressing external database from JSP
Hi,
thanks a lot for that help.
Unfortunately I am still stuck with another error now. Using the code below
causes:
javax.servlet.ServletException: Resource loader error in file '/testdb.jsp'
Root cause:
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: -1 in the jsp file: null
Generated servlet error:
[javac] Since fork is true, ignoring compiler setting.
[javac] Compiling 1 source file
[javac] Since fork is true, ignoring compiler setting.
[javac]
/var/jakarta-tomcat-4.1.24/work/Standalone/localhost/intra/WEB-INF/jsp/offli
ne/testdb_jsp_jsp.java:19: unreported exception
java.lang.ClassNotFoundException; must be caught or declared to be thrown
[javac] Class.forName(sDbDrv);
[javac] ^
[javac] 1 error
I think it has something to do with the installed driver. But I cannot
figure out what. The Driver is installed like this:
intra:/var/jakarta-tomcat-4.1.24/webapps/intra/WEB-INF/lib# jar -tvf
msbase.jar
31575 Tue Oct 07 16:05:54 CEST 2003 META-INF/MANIFEST.MF
31683 Tue Oct 07 16:05:56 CEST 2003 META-INF/zigbert.sf
2527 Tue Oct 07 16:05:56 CEST 2003 META-INF/zigbert.rsa
1316 Fri Aug 08 17:23:56 CEST 2003
com/microsoft/jdbc/base/BaseBatchUpdateException.class
5526 Fri Aug 08 17:23:56 CEST 2003 com/microsoft/jdbc/base/BaseBlob.class
1524 Fri Aug 08 17:23:56 CEST 2003
com/microsoft/jdbc/base/BaseBlobInputStream.class
1631 Fri Aug 08 17:23:56 CEST 2003
com/microsoft/jdbc/base/BaseBlobOutputStream.class
327 Fri Aug 08 17:23:56 CEST 2003 com/microsoft/jdbc/base/BaseBuildId.class
7362 Fri Aug 08 17:23:56 CEST 2003
com/microsoft/jdbc/base/BaseCallableStatement.class
587 Fri Aug 08 17:23:56 CEST 2003
com/microsoft/jdbc/base/BaseCallEscape.class
2709 Fri Aug 08 17:23:56 CEST 2003
com/microsoft/jdbc/base/BaseCharacterStreamWrapper.class
1615 Fri Aug 08 17:23:56 CEST 2003
com/microsoft/jdbc/base/BaseClassUtility.class
7594 Fri Aug 08 17:23:56 CEST 2003 com/microsoft/jdbc/base/BaseClob.class
2012 Fri Aug 08 17:23:56 CEST 2003
com/microsoft/jdbc/base/BaseClobInputStream.class
2224 Fri Aug 08 17:23:56 CEST 2003
com/microsoft/jdbc/base/BaseClobOutputStream.class
2445 Fri Aug 08 17:23:56 CEST 2003 com/microsoft/jdbc/base/BaseColumn.class
2135 Fri Aug 08 17:23:56 CEST 2003 com/microsoft/jdbc/base/BaseColumns.class
10771 Fri Aug 08 17:23:56 CEST 2003
com/microsoft/jdbc/base/BaseConnection.class
1601 Fri Aug 08 17:23:56 CEST 2003
com/microsoft/jdbc/base/BaseConnectionPool.class
1489 Fri Aug 08 17:23:56 CEST 2003
com/microsoft/jdbc/base/BaseConnectionProperties.class
1412 Fri Aug 08 17:23:56 CEST 2003
com/microsoft/jdbc/base/BaseConnectionStartup.class
19534 Fri Aug 08 17:23:56 CEST 2003 com/microsoft/jdbc/base/BaseData.class
37811 Fri Aug 08 17:23:56 CEST 2003
com/microsoft/jdbc/base/BaseDatabaseMetaData.class
3268 Fri Aug 08 17:23:56 CEST 2003 com/microsoft/jdbc/base/BaseDriver.class
1518 Fri Aug 08 17:23:56 CEST 2003
com/microsoft/jdbc/base/BaseDriverPropertyInfos.class
959 Fri Aug 08 17:23:56 CEST 2003 com/microsoft/jdbc/base/BaseEscape.class
Am I on the right track? Can someone help?
Any help is appreciated!
Thanks
Björn
>>> beffe at beffe.de 30.04.2004 22:04:58 >>>
It should look like this:
<html>
<body>
<%@ page
import = "java.io.*"
import = "java.lang.*"
import = "java.sql.*"
%>
<%!
static String sDbDrv = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
static String sDbUrl = "jdbc:microsoft:sqlserver://server/bla";
String sSql = "SELECT * from Example";
static {
Class.forName(sDbDrv);
}
%>
<%
Connection cn = DriverManager.getConnection(sDbUrl, "bla", "bla");
Statement st = cn.createStatement();
ResultSet rs = st.executeQuery(sSql);
ResultSetMetaData meta = rs.getMetaData();
out.println("Got results:");
while
(rs.next() == true)
{
// Which Column?
out.println("Working Title: ");
String a = rs.getString("P_TITEL");
out.print(a);
//Which Column?
out.print("Projektziel: ");
String b = rs.getString("P_ZIEL");
out.print(b);
}
try {
if (rs!=null) rs.close();
if (st!=null) st.close();
if (cn!=null) cn.close();
}
catch (Exception ignore) {}
%>
</body>
</html>
----- Original Message -----
From: "Stephan Hartmann" <beffe at beffe.de>
To: <opencms-dev at opencms.org>
Sent: Friday, April 30, 2004 8:55 PM
Subject: Re: [opencms-dev] Addressing external database from JSP
> Hi Björn,
>
> inside of a definition block (starting with "<%!" ) you can only place
> member variable an method definitions, but not normal code. You have to
> close this block with a "%>" after the method jspInit's closing bracket
and
> open a code block for the rest with "<%".
> After the closing bracket of the while loop you should also place some
clean
> up:
> try {
> if (rs!=null) rs.close();
> if (st!=null) st.close();
> if (cn!=null) cn.close();
> }
> catch (Exception ignore) {}
>
> Bye,
> Stephan
>
> ----- Original Message -----
> From: "Björn Schlueter" <bschlueter at lenord.de>
> To: <opencms-dev at opencms.org>
> Sent: Friday, April 30, 2004 10:40 AM
> Subject: [opencms-dev] Addressing external database from JSP
>
>
> Hello there,
>
> as a newbie I am stuck with this little problem.
> I am trying to access from opencms an external datebase (namely a ms sql
> 2000 server).
> I know I should use a servlet to access that db, but right know i want to
> use a jsp as a shortcut.
>
> This ist what my code looks like:
>
> <html>
> <body>
> <%@ page
> import = "java.io.*"
> import = "java.lang.*"
> import = "java.sql.*"
> %>
>
> <%!
> String sDbDrv = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
> String sDbUrl = "jdbc:microsoft:sqlserver://server/bla";
> String sSql = "SELECT * from Example";
>
> public void jspInit()
> {
> Class.forName(sDbDrv);
> Connection cn = DriverManager.getConnection(sDbUrl, "bla", "bla");
> }
>
> Statement st = cn.createStatement();
> ResultSet rs = st.executeQuery(sSql);
>
> ResultSetMetaData meta = rs.getMetaData();
> out.println("Got results:");
>
> while
> (rs.next() == true)
> {
> // Which Column?
> out.println("Working Title: ");
> String a = rs.getString("P_TITEL");
> out.print(a);
>
> //Which Column?
> out.print("Projektziel: ");
> String b = rs.getString("P_ZIEL");
> out.print(b);
> }
> %>
> </body>
> </html>
>
>
> I really don't know, why OpenCMS does not want to compile that jsp.
>
> I get the following messages:
>a from Example";
sta
> javax.servlet.ServletException: Resource loader error in file
'/testdb.jsp'
>
> Root cause:
> org.apache.jasper.JasperException: Unable to compile class for JSP
>
> An error occurred at line: -1 in the jsp file: null
>
> I am pretty much helpless right know. I couldn't find help at google or
> relevant java forums!
>
> Can somone of you give me a hint?
>
> Thanks
>
> Björn
>
>
> _______________________________________________
> This mail is send to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> http://mail.opencms.org/mailman/listinfo/opencms-dev
>
>
> _______________________________________________
> This mail is send to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> http://mail.opencms.org/mailman/listinfo/opencms-dev
>
_______________________________________________
This mail is send to you from the opencms-dev mailing list
To change your list options, or to unsubscribe from the list, please visit
http://mail.opencms.org/mailman/listinfo/opencms-dev
_______________________________________________
This mail is send to you from the opencms-dev mailing list
To change your list options, or to unsubscribe from the list, please visit
http://mail.opencms.org/mailman/listinfo/opencms-dev
_______________________________________________
This mail is send to you from the opencms-dev mailing list
To change your list options, or to unsubscribe from the list, please visit
http://mail.opencms.org/mailman/listinfo/opencms-dev
More information about the opencms-dev
mailing list