I am having problems connecting to SQL Server. I always get :
java.lang.ClassNotFoundException:
com.microsoft.sqlserver.jdbc.SQLServerDriver
My connection code works because I have tried it out separately and I
don't get that error.
I have other jar files imported through eclipse and haven't had a
problem with it.
Any help?
Thanks.
Of course I'm doing it with the server...
I import
import java.sql.*;
import com.microsoft.sqlserver.jdbc.*;
and have this:
<snip>
String connectionUrl = "jdbc:sqlserver://*****:
1433;databaseName=***;user=***;password=***";
// Declare the JDBC objects.
int count = 0;
String result = "";
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try{
// Establish the connection.
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection(connectionUrl);
// Create and execute an SQL statement that returns some
data.
String SQL = "SELECT Name FROM ODB_Terms";
stmt = con.createStatement();
rs = stmt.executeQuery(SQL);
while(rs.next()){
count++;
}
result = ""+count;
}
catch(Exception e){
result = e.toString();
}
return result;
</snip>
and it's returning the catch...
What am I doing wrong?
On Aug 8, 1:21 pm, "Chad Bourque" <chad...@gmail.com> wrote:
> Juan,
>
> Are you trying to do that from the server or client? You can't do it from
> the client. Only javascript runs there and this class is not emulated by GWT
> (check the online docs for emulated classes). You should be able to do this
> on the server without problems. I know I and many others are connecting to
> databases. Oh, and to communicate between the client and server, use RPC
> (again, just check the docs).
>
> HTH,
> Chad
>
> On 8/8/07, Juan Sequeda <juanfeder...@gmail.com> wrote:
>
>
>
>
>
> > Hi.
>
> > I am having problems connecting to SQL Server. I always get :
>
> > java.lang.ClassNotFoundException:
> > com.microsoft.sqlserver.jdbc.SQLServerDriver
>
> > My connection code works because I have tried it out separately and I
> > don't get that error.
>
> > I have other jar files imported through eclipse and haven't had a
> > problem with it.
>
> > Any help?
>
> > Thanks.
>
> --
> There are two types of people in the world:
> * Those who need closure
Do I have to change something in my gwt.xml file?
I have all the jars in C:\gwt\tomcat\webapps\ROOT\WEB-INF
but I still can't connect to sql server. Any help?
java.lang.ClassNotFoundException:
com.microsoft.sqlserver.jdbc.SQLServerDriver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at
com.morphster.server.TreeServiceImpl.getRootsBD(TreeServiceImpl.java:
92)
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
com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(Remot
eServiceServlet.java:281)
at
com.google.gwt.user.server.rpc.RemoteServiceServlet.doPost(RemoteServ
iceServlet.java:167)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:
709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:
802)
at
com.google.gwt.dev.shell.GWTShellServlet.service(GWTShellServlet.java
:248)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:
802)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:237)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:157)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:214)
at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:104)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:520)
at
org.apache.catalina.core.StandardContextValve.invokeInternal(Standard
ContextValve.java:198)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:152)
at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:104)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:520)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:137)
at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:104)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:118)
at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:102)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:520)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:109)
at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:104)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:520)
at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at
org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:16
0)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:799)
at org.apache.coyote.http11.Http11Protocol
$Http11ConnectionHandler.proce
ssConnection(Http11Protocol.java:705)
at
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java
:577)
at org.apache.tomcat.util.threads.ThreadPool
$ControlRunnable.run(ThreadP
ool.java:683)
at java.lang.Thread.run(Unknown Source)
Thanks in advance for all your help. I have been on this for a while
and now I am kind of desperate. Thanks
in YOUR PROJECT's Context add the jar files to WEB-INF/lib ... note
the "lib" at the end...
And then my packages are in C:\gwt\src\com\morphster
The only WEB-INF/lib I found on my harddrive (I searched it all) was C:
\gwt\tomcat\webapps\ROOT\WEB-INF
The thing is I am also using another jar file and that has no problem
at all.. there is only problems with the sqlserver.
Thanks for your help.
One thing to be careful of, sometimes the Tomcat container needs to
manage the jar files in $CATALINA_HOME/common/lib. I know this is an
issue with Oracle and connection pooling, I had copies of the Oracle
JDBC jar file in the local app's WEB-INF/lib and then I tried
$CATALINA_HOME/shared/lib - both caused a class not found error. It
didn't work until I placed the file in common/lib where the Tomcat
container could use them too.
Only web applications can access and use jar files in shared/lib.
I don't know if the MS SQL driver is having the same issue or not, but
I just wanted to point that out.
Juan, how do you have Tomcat installed?
>
> One thing to be careful of, sometimes the Tomcat container needs to
> manage the jar files in $CATALINA_HOME/common/lib. I know this is an
> issue with Oracle and connection pooling, I had copies of the Oracle
> JDBC jar file in the local app's WEB-INF/lib and then I tried
> $CATALINA_HOME/shared/lib - both caused a class not found error. It
> didn't work until I placed the file in common/lib where the Tomcat
> container could use them too.
>
> Only web applications can access and use jar files in shared/lib.
>
> I don't know if the MS SQL driver is having the same issue or not, but
> I just wanted to point that out.
>
> Juan, how do you have Tomcat installed?
One thing to clarify about my post. I was thinking a traditional
Tomcat configuration, not running it in hosted mode. But, I think you
can create a common/lib directory structure underneath the Tomcat
directory in your project folder, place your MS JDBC driver files in
there and it should do the same thing.
I need it to work in the hosted mode.
the tomcat directory in the gwt already has the WEB-INF (C:\gwt\tomcat
\webapps\ROOT\WEB-INF\lib) and inside the lib directory I have the
sqljdbc.jar, but it still doesn't work?
Do I have to change something in the web.xml file? If so, what is it?
Thanks a lot!!!!
But then how do I use the Run dialog (don't I have to a main to use
it?)
On Aug 15, 10:33 am, "Chad Bourque" <chad...@gmail.com> wrote:
> Juan,
>
> In Eclipse, did you add it to the Classpath as an External JAR in the Run
> dialog? I believe that's all you should need to do to get it to work in
> hosted mode. If you want it to work when you run the shell script (generated
> by the appCreator script), you have to add it to the classpath in that
> script (I believe).
>
> I generally don't worry about changing the shell script as I never run it
> that way. I always either just Run from Eclipse or deploy to my external
> Tomcat via a WAR file. So, the only things I do is add it to the Eclipse
> dialog as stated above for development and debugging, and I follow my steps
> listed on the web (link provided earlier in this thread) for deployed
> testing.
>
> HTH,
> Chad
>
> --
> There are two types of people in the world:
>
> the tomcat directory in the gwt already has the WEB-INF (C:\gwt\tomcat
> \webapps\ROOT\WEB-INF\lib) and inside the lib directory I have the
> sqljdbc.jar, but it still doesn't work?
>
> Do I have to change something in the web.xml file? If so, what is it?
>
I was just pointing out that when I have worked with Oracle drivers
with a classic tomcat configuration (not GWT), I got the same class
not found errors that you mentioned. I had placed my JDBC jar files
in the local WEB-INF/lib and then later in shared/lib, but I kept
getting the same error. After some poking around and reading the
Tomcat classloader [1] documentation like 10 times, I realized that
Tomcat needed access to the driver jars, but by placing them in WEB-
INF/lib or shared/lib, it was unable to 'see' them. The only way it
could access them was through common/lib. Since GWT hosted mode seems
to use an embedded Tomcat instance, I figure it might be the same
issue.
If the problem lies where I think it is, you shouldn't have to modify
anything in web.xml, etc.
The last thing I want to do is confuse the thread even more, I may be
really off base, but I saw the commonality between your problem and
mine, and though I'd offer my two cents.
[1] - http://tomcat.apache.org/tomcat-5.5-doc/class-loader-howto.html