jinghuei
asked on
newbie question: Jbuilder2006 database connect ok, but jsp file cannot create connection
I am learning how to use Jbuilder2006 to develop a webapp.
Before I get to Jbuilder2006, I use a jsp file for Tomcat5.5 , JDK1.5 and MS sqlserver2000 to test an JNDI connection.
It works fine.
When I create a jubilder project for it, got an error msg:---cannot create JDBC driver for class " " to URL null.
I had have seen data of my database use DATABASE PILOT,
and add the 3 jar files of sqlserver as requried library in Project Property.
------- The ms sqlserver driver should have loaded correctly.
The server.xml file under %Jbuilder_JAVA_Home%/conf and the web.xml file are set as before.
and the jsp file is as:
-------------------------- ---------- ---------- ---------- --------
<%@ page contentType="text/html; charset=Big5"
import="java.sql.*, javax.sql.*, javax.naming.*"%>
<HTML>
<HEAD>
<TITLE>Get data with JNDI connection</TITLE>
</HEAD>
<BODY>
<CENTER>
<FONT SIZE = 5 COLOR = blue>Get data with JNDI connection</FONT>
</CENTER>
<HR>
<P></P>
<CENTER>
<%
try{
System.out.println("1----- ---------- ---------- --");
String dbName = "java:comp/env/jdbc/ACCM";
System.out.println("2----- ---------- ----");
InitialContext ic = new InitialContext();
System.out.println("3----- ---------- ---------- --");
DataSource ds = (DataSource) ic.lookup(dbName);
System.out.println("4----- ---------- ---------- --");
Connection con = ds.getConnection();
System.out.println("5----- ---------- ---------- --");
Statement stmt = con.createStatement();
ResultSet rs;
rs = stmt.executeQuery("SELECT * FROM dept");
%>
<TABLE bgcolor=DodgerBlue>
<TR bgcolor=SkyBlue>
<TD><B>userid</B></TD><TD> <B>pwd</B> </TD><TD>< B>clevel/B ></TD>
</TR>
<%
while (rs.next())
{
%>
<TR bgcolor=LightGoldenrodYell ow>
<TD><B><%= rs.getString("userid") %></B></TD>
<TD><B><%= rs.getString("pwd") %></B></TD>
<TD><B><%= rs.getString("clevel") %></B></TD>
</TR>
<%
}
if(rs != null) rs.close();
if(stmt != null) stmt.close();
if(con != null) con.close();
} catch(Exception ex) {
System.out.println(ex.toSt ring());
}
%>
</TABLE>
</CENTER>
</BODY>
</HTML>
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
The message of the execution "http://localhost:8080/JNDI.jsp" showed under Tomcat as following:
//**---------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- -----
1------------------------- --
2------------------------- --
3------------------------- --
4------------------------- --
org.apache.tomcat.dbcp.dbc p.SQLNeste dException :Cannot create JDBC driverof class '' for connect URL 'null'.
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- */
That meant it cannot get to '5'--the connection.
Is there other setting should be done?
I need help.
Thanks,experts
Catherine
Before I get to Jbuilder2006, I use a jsp file for Tomcat5.5 , JDK1.5 and MS sqlserver2000 to test an JNDI connection.
It works fine.
When I create a jubilder project for it, got an error msg:---cannot create JDBC driver for class " " to URL null.
I had have seen data of my database use DATABASE PILOT,
and add the 3 jar files of sqlserver as requried library in Project Property.
------- The ms sqlserver driver should have loaded correctly.
The server.xml file under %Jbuilder_JAVA_Home%/conf and the web.xml file are set as before.
and the jsp file is as:
--------------------------
<%@ page contentType="text/html; charset=Big5"
import="java.sql.*, javax.sql.*, javax.naming.*"%>
<HTML>
<HEAD>
<TITLE>Get data with JNDI connection</TITLE>
</HEAD>
<BODY>
<CENTER>
<FONT SIZE = 5 COLOR = blue>Get data with JNDI connection</FONT>
</CENTER>
<HR>
<P></P>
<CENTER>
<%
try{
System.out.println("1-----
String dbName = "java:comp/env/jdbc/ACCM";
System.out.println("2-----
InitialContext ic = new InitialContext();
System.out.println("3-----
DataSource ds = (DataSource) ic.lookup(dbName);
System.out.println("4-----
Connection con = ds.getConnection();
System.out.println("5-----
Statement stmt = con.createStatement();
ResultSet rs;
rs = stmt.executeQuery("SELECT * FROM dept");
%>
<TABLE bgcolor=DodgerBlue>
<TR bgcolor=SkyBlue>
<TD><B>userid</B></TD><TD>
</TR>
<%
while (rs.next())
{
%>
<TR bgcolor=LightGoldenrodYell
<TD><B><%= rs.getString("userid") %></B></TD>
<TD><B><%= rs.getString("pwd") %></B></TD>
<TD><B><%= rs.getString("clevel") %></B></TD>
</TR>
<%
}
if(rs != null) rs.close();
if(stmt != null) stmt.close();
if(con != null) con.close();
} catch(Exception ex) {
System.out.println(ex.toSt
}
%>
</TABLE>
</CENTER>
</BODY>
</HTML>
--------------------------
The message of the execution "http://localhost:8080/JNDI.jsp" showed under Tomcat as following:
//**----------------------
1-------------------------
2-------------------------
3-------------------------
4-------------------------
org.apache.tomcat.dbcp.dbc
--------------------------
That meant it cannot get to '5'--the connection.
Is there other setting should be done?
I need help.
Thanks,experts
Catherine
ASKER
Hi,bloodred sun:
Thank you for responding.
The url I put in Datapilot is -- jdbc:microsoft.sqlserver:/ /localhost :1433
(**just as same as in the server.xml but without the databasename and the password)
and the driver I put in Data pilot is -- com.microsoft.jdbc.sqlserv er.SQLServ erDriver
(**just as same as in the server.xml ).
I don't understand.
Since I can retrieve table data of database using Data pilot,
could there still be the problem?
Catherine
Thank you for responding.
The url I put in Datapilot is -- jdbc:microsoft.sqlserver:/
(**just as same as in the server.xml but without the databasename and the password)
and the driver I put in Data pilot is -- com.microsoft.jdbc.sqlserv
(**just as same as in the server.xml ).
I don't understand.
Since I can retrieve table data of database using Data pilot,
could there still be the problem?
Catherine
ASKER
I check my CLASS_PATH that includes the 3 jar files but in the sqlserver driver installed directory.
The path of 3 classes inside the new library created in "My Tools\Configure Libraries" was different.
The old path is set to "%Jbuilder_Home/thirdparty \jakarta-t omcat-5.5. 9\common\l ib" , there is a copy of these 3 files.
Now I change the libray files to the path to the sqlserver driver installed directory ,
so the specifed drivers are put in the CLASS_PATH.
Then I restart Jbuilder, and run the jsp file.
The error msg -- "Cannot create JDBC driverof class '' for connect URL 'null' is gone.
There is a blank web -- nothing comes out at all with no error msg.
The web even don't have " title" part come out.
I wonder where I can check the log and fix it?
There is no log under "%Jbuilder_Home/thirdparty \jakarta-t omcat-5.5. 9\log" at all.
Thank for help in advance>
catherine
The path of 3 classes inside the new library created in "My Tools\Configure Libraries" was different.
The old path is set to "%Jbuilder_Home/thirdparty
Now I change the libray files to the path to the sqlserver driver installed directory ,
so the specifed drivers are put in the CLASS_PATH.
Then I restart Jbuilder, and run the jsp file.
The error msg -- "Cannot create JDBC driverof class '' for connect URL 'null' is gone.
There is a blank web -- nothing comes out at all with no error msg.
The web even don't have " title" part come out.
I wonder where I can check the log and fix it?
There is no log under "%Jbuilder_Home/thirdparty
Thank for help in advance>
catherine
ASKER
When I run the program and get blank web.
The message box of the Tomcat shows as below:
-------------------------- ---------- ---------- ---------- ----
C:\JBuilder2006\jdk1.5\bin \javaw -classpath "C:\JBuilder2006\thirdpart y\jakarta- tomcat-5.5 .9\bin\boo tstrap.jar ;C:\Progra m Files\Microsoft SQL Server 2000 Driver for JDBC\lib\msbase.jar;C:\Pro gram Files\Microsoft SQL Server 2000 Driver for JDBC\lib\mssqlserver.jar;C :\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\msutil.jar;C:\JBu ilder2006\ jdk1.5\lib \tools.jar " "-Dcatalina.home=C:/JBuild er2006/thi rdparty/ja karta-tomc at-5.5.9" org.apache.catalina.startu p.Bootstra p -config D:\jbproject\testDB\Tomcat \conf\serv er8080.xml start
2006/2/13 Afternoon 07:07:03 org.apache.coyote.http11.H ttp11Proto col init
Message: Initializing Coyote HTTP/1.1 on http-8080
2006/2/13 Afternoon 07:07:03 org.apache.catalina.startu p.Catalina load
Message: Initialization processed in 1125 ms
2006/2/13 Afternoon 07:07:03 org.apache.catalina.core.S tandardSer vice start
Message: Starting service Catalina
2006/2/13 Afternoon 07:07:03 org.apache.catalina.core.S tandardEng ine start
Message: Starting Servlet Engine: Apache Tomcat/5.5.9
2006/2/13 Afternoon 07:07:03 org.apache.catalina.core.S tandardHos t start
Message: XML validation disabled
2006/2/13 Afternoon 07:07:04 org.apache.catalina.realm. JAASRealm setContainer
Message: Set JAAS app name Catalina
2006/2/13 Afternoon 07:07:05 org.apache.coyote.http11.H ttp11Proto col start
Message: Starting Coyote HTTP/1.1 on http-8080
2006/2/13 Afternoon 07:07:05 org.apache.catalina.startu p.Catalina start
Message: Server startup in 2047 ms
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- -
Does it help to trace why the blank web comes out?
Urge to have your help!
Thank you.
Catherine
The message box of the Tomcat shows as below:
--------------------------
C:\JBuilder2006\jdk1.5\bin
2006/2/13 Afternoon 07:07:03 org.apache.coyote.http11.H
Message: Initializing Coyote HTTP/1.1 on http-8080
2006/2/13 Afternoon 07:07:03 org.apache.catalina.startu
Message: Initialization processed in 1125 ms
2006/2/13 Afternoon 07:07:03 org.apache.catalina.core.S
Message: Starting service Catalina
2006/2/13 Afternoon 07:07:03 org.apache.catalina.core.S
Message: Starting Servlet Engine: Apache Tomcat/5.5.9
2006/2/13 Afternoon 07:07:03 org.apache.catalina.core.S
Message: XML validation disabled
2006/2/13 Afternoon 07:07:04 org.apache.catalina.realm.
Message: Set JAAS app name Catalina
2006/2/13 Afternoon 07:07:05 org.apache.coyote.http11.H
Message: Starting Coyote HTTP/1.1 on http-8080
2006/2/13 Afternoon 07:07:05 org.apache.catalina.startu
Message: Server startup in 2047 ms
--------------------------
Does it help to trace why the blank web comes out?
Urge to have your help!
Thank you.
Catherine
ASKER
Hi, bloodredsun:
**This indicates that the specified driver cannot be found on the classpath. Check the availability of the driver and the database url and driver name
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---
What should the CLASS_PATH contain for JBUILDER with JDBC for sqlserver?
Does CLASS_PATH contains
C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\msbase.jar;C:\Pro gram Files\Microsoft SQL Server 2000 Driver for JDBC\lib\mssqlserver.jar;C :\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\msutil.jar;
is enough for Jbuilder?
Catherine
**This indicates that the specified driver cannot be found on the classpath. Check the availability of the driver and the database url and driver name
--------------------------
What should the CLASS_PATH contain for JBUILDER with JDBC for sqlserver?
Does CLASS_PATH contains
C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\msbase.jar;C:\Pro
is enough for Jbuilder?
Catherine
ASKER
I reinstall my Jbuilder2006 and redo some configurations and open the log.
Now I have the message of Tomcat becomes:
1------------------------- --
2------------------------- -
3------------------------- --
4------------------------- --
DriverManager.getDriver("n ull")
DriverManager.initialize: jdbc.drivers = null
JDBC DriverManager initialized
getDriver: no suitable driver
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.get Driver(Dri verManager .java:243)
at org.apache.tomcat.dbcp.dbc p.BasicDat aSource.cr eateDataSo urce(Basic DataSource .java:773)
at org.apache.tomcat.dbcp.dbc p.BasicDat aSource.ge tConnectio n(BasicDat aSource.ja va:540)
at org.apache.jsp.sqlcon_jsp. _jspServic e(org.apac he.jsp.sql con_jsp:68 )
at org.apache.jasper.runtime. HttpJspBas e.service( HttpJspBas e.java:97)
at javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 802)
at org.apache.jasper.servlet. JspServlet Wrapper.se rvice(JspS ervletWrap per.java:3 22)
at org.apache.jasper.servlet. JspServlet .serviceJs pFile(JspS ervlet.jav a:291)
at org.apache.jasper.servlet. JspServlet .service(J spServlet. java:241)
at javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 802)
at org.apache.catalina.core.A pplication FilterChai n.internal DoFilter(A pplication FilterChai n.java:252 )
at org.apache.catalina.core.A pplication FilterChai n.doFilter (Applicati onFilterCh ain.java:1 73)
at org.apache.catalina.core.S tandardWra pperValve. invoke(Sta ndardWrapp erValve.ja va:213)
at org.apache.catalina.core.S tandardCon textValve. invoke(Sta ndardConte xtValve.ja va:178)
at org.apache.catalina.core.S tandardHos tValve.inv oke(Standa rdHostValv e.java:126 )
at org.apache.catalina.valves .ErrorRepo rtValve.in voke(Error ReportValv e.java:105 )
at org.apache.catalina.core.S tandardEng ineValve.i nvoke(Stan dardEngine Valve.java :107)
at org.apache.catalina.connec tor.Coyote Adapter.se rvice(Coyo teAdapter. java:148)
at org.apache.coyote.http11.H ttp11Proce ssor.proce ss(Http11P rocessor.j ava:856)
at org.apache.coyote.http11.H ttp11Proto col$Http11 Connection Handler.pr ocessConne ction(Http 11Protocol .java:744)
at org.apache.tomcat.util.net .PoolTcpEn dpoint.pro cessSocket (PoolTcpEn dpoint.jav a:527)
at org.apache.tomcat.util.net .LeaderFol lowerWorke rThread.ru nIt(Leader FollowerWo rkerThread .java:80)
at org.apache.tomcat.util.thr eads.Threa dPool$Cont rolRunnabl e.run(Thre adPool.jav a:684)
at java.lang.Thread.run(Threa d.java:595 )
SQLException: SQLState(08001)
org.apache.tomcat.dbcp.dbc p.SQLNeste dException : Cannot create JDBC driver of class '' for connect URL 'null'
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---
I don't know why it gets the lines:
-------------------------- ---------- ---------- ---------- ---
DriverManager.getDriver("n ull")
DriverManager.initialize: jdbc.drivers = null
JDBC DriverManager initialized
getDriver: no suitable driver
-------------------------- ---------- ---------- ---------- --
How to fix the problem?
(I can retrieve data from database pilot, and sure to put the sqldriver files in my CLASS_PATH.)
Any help will be very much appreciated.
Catherine
Now I have the message of Tomcat becomes:
1-------------------------
2-------------------------
3-------------------------
4-------------------------
DriverManager.getDriver("n
DriverManager.initialize: jdbc.drivers = null
JDBC DriverManager initialized
getDriver: no suitable driver
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.get
at org.apache.tomcat.dbcp.dbc
at org.apache.tomcat.dbcp.dbc
at org.apache.jsp.sqlcon_jsp.
at org.apache.jasper.runtime.
at javax.servlet.http.HttpSer
at org.apache.jasper.servlet.
at org.apache.jasper.servlet.
at org.apache.jasper.servlet.
at javax.servlet.http.HttpSer
at org.apache.catalina.core.A
at org.apache.catalina.core.A
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.valves
at org.apache.catalina.core.S
at org.apache.catalina.connec
at org.apache.coyote.http11.H
at org.apache.coyote.http11.H
at org.apache.tomcat.util.net
at org.apache.tomcat.util.net
at org.apache.tomcat.util.thr
at java.lang.Thread.run(Threa
SQLException: SQLState(08001)
org.apache.tomcat.dbcp.dbc
--------------------------
I don't know why it gets the lines:
--------------------------
DriverManager.getDriver("n
DriverManager.initialize: jdbc.drivers = null
JDBC DriverManager initialized
getDriver: no suitable driver
--------------------------
How to fix the problem?
(I can retrieve data from database pilot, and sure to put the sqldriver files in my CLASS_PATH.)
Any help will be very much appreciated.
Catherine
ASKER
Problem solved!
It's wrong for me to change the server.xml under the "%Jbuilder_Home/thirdparty \jakarta-t omcat-5.5. 9\conf".
I should modify the server8080.xml under %myproject%/Tomcat/conf.
I wonder the help on-line book of Jbuuilder says it.
Too happy to have it solved!
Anyway! Thank everybody!
Catherine
It's wrong for me to change the server.xml under the "%Jbuilder_Home/thirdparty
I should modify the server8080.xml under %myproject%/Tomcat/conf.
I wonder the help on-line book of Jbuuilder says it.
Too happy to have it solved!
Anyway! Thank everybody!
Catherine
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This indicates that the specified driver cannot be found on the classpath. Check the availability of the driver and the database url and driver name