• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JDBC Confusion

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I am trying to connect to a SQL Server 2008 R2 instance running on the same machine as my Servlet is, but regardless of how I cut things I get the following error:

[code]
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (I/O Error: DB server closed connection.)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
at RTX.init(RTX.java:37)
...
[/code]

The SQL instance is configured to run only TCP/IP and supports Mixed Mode Authentication, the user and password I am using can connect to the instance using SQL Management Studio.

With that said I am using jtds-1.2.5 with the jar file in the Tomcat/lib dir and the ntlmauth.dll in the servlet's WEB-INF/libs directory. In addition to this I have this in the context.xml file:

[code]<Resource name="jdbc/RTXDS" auth="Container" type="javax.sql.DataSource" username="Me" password="NotTellingYou" driverClassName="net.sourceforge.jtds.jdbc.Driver" url="jdbc:jtds:sqlserver://127.0.0.1:1433;databaseName=master;" maxActive="8" maxIdle="4"/>[/code]

And lastly of course is the Java code itself:
[code]
private Connection connection ;
private DataSource ds ;
public void init (ServletConfig config) throws ServletException
{
Context initContext;
try {
initContext = new InitialContext();
Context envContext = (Context) initContext.lookup("java:comp/env") ;
ds = (DataSource) envContext.lookup("jdbc/RTXDS") ;
} catch (NamingException ne) {
ne.printStackTrace();
}
try
{
if (ds != null)
{
connection = ds.getConnection() ;
}
}
catch (SQLException e)
{
e.printStackTrace();
}
}
[/code]

Can anyone help me out here please?
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you tried looking in the SQL server logs or event logs of the machine your DB is on? There might be a clue in there. Does this happen after a period of time or just as soon as you try to connect?
 
Bill Moo
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul,

I got this from the event viewer!

"Encryption is required to connect to this server but the client library does not support encryption; the connection has been closed. Please upgrade your client library."

But it doesn't need encryption to connect so I don't understand this, am I missing a setting somewhere? Also, I get this error as soon as I try to connect at Servlet startup.

 
Marshal
Posts: 28245
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all, why use a complicated thing like Tomcat to test your JDBC connections? Do it the simple way first: write a plain old Java application which does nothing but make a JDBC connection. When you have that working and you have identified the correct setup parameters, then you can plug those into Tomcat.

And I have to say I'm very dubious about this NTLM idea. I switched to using the JTDS driver for SQL Server specifically to avoid that message about encryption being required on the connection, I got that message from Microsoft's driver but not from JTDS. And I don't use NTLM to connect in any way, I just configured the user ID and password the same way you did and made sure that SQL Server was configured to accept connections via IP.
 
Bill Moo
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul,

Thanks for the reply, but it only serves to add to my confusion. I certainly do not want to come across as ungreatful but are the methods used totally different? I don't think an application uses a context.xml or web.xml files so I do not see the relevance here.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic