I have the following in C:/Tomcat6/conf/context.xml:
<Context>
<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<ResourceLink global="jdbc/MyDatasource" name="jdbc/MyDatasource" type="javax.sql.DataSource"/>
</Context>
and the following in C:/Tomcat6/conf/server.xml:
<Resource name="jdbc/MyDatasource"
auth="Container"
driverClassName="net.sourceforge.jtds.jdbc.Driver"
maxactive="100"
maxidle="30"
maxwait="10000"
type="javax.sql.DataSource"
jdbcUrl="jdbc:jtds:sqlserver://localhost/SAFEHOUSE-UK;integratedSecurity=true;">
I have jtds-1.2.5.jar in C:/Tomcat6/lib.
Yet when I hit my application I get the following:
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC
driver of class 'net.sourceforge.jtds.jdbc.Driver' for connect URL
'null' at
org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1452)
at
org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
at
org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
at
com.safehouse.safeservices.authenticate.AdminLoginForm.getpassword(Unknown
Source)
Any help would be much appreciated
1、modify the connection url
jdbcUrl="jdbc:jtds:sqlserver://localhost:1305;DatabaseName=your databasename"
From Apache Tomcat 6 documentation: https://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html
maybe the mistake was in attribute name, try to use url instead of jdbcUrl
Related
By default, camunda rest api uses H2 database.
I'm unable to locate the file where I can configure the rest api to use Microsoft SQL Server.
Apologies for not being much clear as I am new to camunda.
You can find information's about configure the JDBC connections in the Camunda installation Guide.
For Example for Tomcat (you have to simply edit the driverClassName, url and the credentials).
To configure a JDBC Resource you have to edit the file
$TOMCAT_HOME/conf/server.xml. This could look like the following
example for an H2 database:
<Server>
...
<GlobalNamingResources>
...
<Resource name="jdbc/ProcessEngine"
auth="Container"
type="javax.sql.DataSource"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
uniqueResourceName="process-engine"
driverClassName="org.h2.Driver"
url="jdbc:h2:./camunda-h2-dbs/process-engine;MVCC=TRUE;TRACE_LEVEL_FILE=0"
username="sa"
password=""
maxActive="20"
minIdle="5" />
</GlobalNamingResources>
</Server>
For JBoss or Wildfly you have to edit the standalone/configuration/standalone.xml:
Add a datasource and driver tag, which could like the following, to the datasources.
<datasource jta="true" enabled="true" use-java-context="true" use-ccm="true"
jndi-name="java:jboss/datasources/ProcessEngine"
pool-name="ProcessEngine">
<connection-url>jdbc:sqlserver://SERVER_NAME:SERVER_PORT;databaseName=DB_NAME</connection-url>
<driver>sqlserver2008</driver>
<security>
<user-name>USERNAME</user-name>
<password>PASSWORD</password>
</security>
<pool>
<min-pool-size>5</min-pool-size>
<max-pool-size>50</max-pool-size>
<prefill>false</prefill>
<use-strict-min>false</use-strict-min>
<flush-strategy>FailingConnectionOnly</flush-strategy>
</pool>
<validation>
<valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.mssql.MSSQLValidConnectionChecker"></valid-connection-checker>
</validation>
</datasource>
<drivers>
<driver name="sqlserver2008" module="com.microsoft">
<driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
</driver>
</drivers>
What is the correct way to setup a SQL Server datasource on Widlfly?
I need to access a SQL Server database from my web application which runs on Wildfly.
I have setup the datasource as follows:
<datasource jta="false" jndi-name="java:jboss/db" pool-name="db" enabled="true" use-ccm="false">
<connection-url>jdbc:jtds:sqlserver://IP_ADDRESS;instance=SQLEXPRESS;DatabaseName=DB</connection-url>
<driver-class>net.sourceforge.jtds.jdbc.Driver</driver-class>
<driver>jtds-1.3.1.jar</driver>
</datasource>
This works fine except that when the SQL Server is restarted, the connection is lost and the datasource doesn't manage to recreate one. So I get errors like:
Invalid state, the Connection object is closed.
This post suggests adding some validation, so I did this:
<validation>
<check-valid-connection-sql>SELECT 1</check-valid-connection-sql>
<validate-on-match>false</validate-on-match>
<background-validation>false</background-validation>
</validation>
But that does not solve the problem and I still get the same "connection closed" error from time to time.
This other post suggests using a DataSource instead of a Driver, so I have added this to my configuration:
<datasource-class>net.sourceforge.jtds.jdbcx.JtdsDataSource</datasource-class>
But when I test the connection I get an exception:
java.sql.SQLException: The serverName property has not been set.
at net.sourceforge.jtds.jdbcx.JtdsDataSource.getConnection(JtdsDataSource.java:150)
I was having the same issue after migrating to WFLY and resolved it by adding the properties.
This is what my complete *-ds.xml looks like:
<?xml version="1.0" encoding="UTF-8"?>
<datasources xmlns="http://www.jboss.org/ironjacamar/schema">
<datasource jndi-name="java:/xxxDS" pool-name="MSSQL">
<connection-url>
jdbc:sqlserver://localhost:1433;database=dbname;charset=UTF-8
</connection-url>
<driver>sqljdbc</driver>
<security>
<user-name>xxx</user-name>
<password>xxx</password>
</security>
<pool>
<!-- default is 0 -->
<min-pool-size>10</min-pool-size>
<!-- default is 20 -->
<max-pool-size>50</max-pool-size>
</pool>
<validation>
<valid-connection-checker
class-name="org.jboss.jca.adapters.jdbc.extensions.mssql.MSSQLValidConnectionChecker" />
<validate-on-match>false</validate-on-match>
<background-validation>true</background-validation>
<check-valid-connection-sql>select 1</check-valid-connection-sql>
<background-validation-millis>10000</background-validation-millis>
</validation>
</datasource>
For me, the valid-connection-checker was not adequate, but by adding the background validation with select 1 it was working.
We have moved over to using the jdbc driver directly from MSFT however:
<driver name="sqljdbc" module="mc.jdbc.sqljdbc">
<driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
</driver>
That also might make a difference, however we had it set up with JBoss AS7 and the jdts driver for a long time.
I have 5 different modules connecting sql server 2008 and 2012 using Tomcat connection pooling.
In the Tomcat7\conf\context.xml
<Resource auth="Container" driverClassName="net.sourceforge.jtds.jdbc.Driver" logAbandoned="true" maxActive="100" maxIdle="30" maxWait="10000" name="jdbc/testservice2" password="abc" removeAbandoned="true" removeAbandonedTimeout="60" type="javax.sql.DataSource"
url="jdbc:jtds:sqlserver://localhost;databaseName=testdb;SelectMethod=Cursor" username="abc"/>
Module 1 - In the Tomcat7\conf\localhost\Module1.XML
<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/Module1">
<Resource name="jdbc/testdb" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000" removeAbandoned="true" removeAbandonedTimeout="60"
username="abc" password="abc" driverClassName="net.sourceforge.jtds.jdbc.Driver"
url="jdbc:jtds:sqlserver://localhost;databaseName=testdb;SelectMethod=Cursor"/>
Module 2 - In the Tomcat7\conf\localhost\Module2.XML
<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/Module2">
<Resource name="jdbc/testdb" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000" removeAbandoned="true" removeAbandonedTimeout="60"
username="abc" password="abc" driverClassName="net.sourceforge.jtds.jdbc.Driver"
url="jdbc:jtds:sqlserver://localhost;databaseName=testdb;SelectMethod=Cursor"/>
</Context>
Module 3 - In the Tomcat7\conf\localhost\Module3.XML
<Context antiJARLocking="true" path="/Module3">
<Resource name="jdbc/testdb" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000" removeAbandoned="true" removeAbandonedTimeout="60"
username="abc" password="abc" driverClassName="net.sourceforge.jtds.jdbc.Driver"
url="jdbc:jtds:sqlserver://localhost;databaseName=testdb;SelectMethod=Cursor"/>
</Context>
Module 4 - In the Tomcat7\conf\localhost\Module4.XML
<Context antiJARLocking="true" path="/Module4">
<Resource name="jdbc/testdb" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000" removeAbandoned="true" removeAbandonedTimeout="60"
username="abc" password="abc" driverClassName="net.sourceforge.jtds.jdbc.Driver"
url="jdbc:jtds:sqlserver://localhost;databaseName=testdb;SelectMethod=Cursor"/>
</Context>
I'm experiencing the below error on QA server as well as staging server?
06-Apr-2015 07:43:28 ERROR DBAccess:49 - I/O Error: Connection reset by peer: socket write error
What's wrong with my Tomcat 7 connection pool configuration? why it's rejected by sql server
You are trying to use all the modules simultaneously in which you have defined the 'Resource' with same name i.e. name="jdbc/testdb" as far as i know this name has to be unique because it is jndi bound with the value you give to name attribute(see tomcat document https://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Resource_Definitions ). If you define a datasource with same name in different modules(web apps) see that they are not in use simultaneously. Somewhere in your server this is happening. To be safe use different name for 'Resource'.
Another thing-Is 'Resource' with name="jdbc/testservice2" being used in any of your five modules you have mentioned. Cause I don't see a connection between any of your five modules with this 'Resource'.
I have a application running on Jboss server. on Jboss it uses JNDI sources for DB connection name cc.xml & iv.xml.(jboss/server/default/deploy/ Both jndi xml are here)
Now i have to deploy the same war on Tomcat and trying to create & access the JNDI sources from tomcat. I made following changes -
Added following code to META-INF/Context.xml
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/R2">
<ResourceLink name="ivrDataSource" global="ivrDataSource" type="javax.sql.DataSource" />
<Resource
name="ivrDataSource"
type="javax.sql.DataSource"
driverClassName="net.sourceforge.jtds.jdbc.Driver"
password=""
maxIdle="2"
maxWait="5000"
username="user"
url="jdbc:jtds:sqlserver://abc:1433;DatabaseName=IVR_GUARDIAN;tds=8.0;lastupdatecount=false;socketKeepAlive=true;"
maxActive="4"/>
<ResourceLink name="ccDataSource" global="ccDataSource" type="javax.sql.DataSource" />
<Resource
name="ccDataSource"
type="javax.sql.DataSource"
driverClassName="net.sourceforge.jtds.jdbc.Driver"
password=""
maxIdle="2"
maxWait="5000"
username="web"
url="jdbc:jtds:sqlserver://xyz:1433;DatabaseName=CC_GUARDIAN;tds=8.0;lastupdatecount=false;socketKeepAlive=true;"
maxActive="4"/>
</Context>
ADDED BELOW TO WEB.XML ----
<!-- FOR TOMCAT DEPLOYMRNT -TESTING -->
<resource-ref>
<description>ccDataSource</description>
<res-ref-name>ccDataSource</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<resource-ref>
<description>ivrDataSource</description>
<res-ref-name>ivrDataSource</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
But i am getting error-
javax.naming.NameNotFoundException: Name ccDataSource,ivrDataSource is not bound in this Context.
Always worked on JBOSS so this is new to me..Missing something here.Please suggest.
You do not have to use <ResourceLink>. Try removing <ResourceLink>s.
<ResourceLink> is used to create a link to a global JNDI resource.
Please see following links for more details.
http://tomcat.apache.org/tomcat-7.0-doc/jndi-resources-howto.html
http://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Resource%20Links
Hope this helps.
I developed a Java web application in Netbeans 6.5 using a MySQL database and Hibernate. Both the development database server and development application server (Tomcat 6) reside on my development machine. Everything works; the application pulls data from the database correctly.
Now, I'm ready to move it to the production server. Again, the DB server and app server are on the same machine. I deploy the WAR file and try to access the application; I can access the static pages but the Servlets that use the database error out with the exception:
org.hibernate.exception.JDBCConnectionException: Cannot open connection
I'm pretty sure the problem relates to Tomcat not knowing about the data source. It seems as if Netbeans handles this for me. I've read that I might need to add a RESOURCE entry so I took some advice from this site which gave me a context.xml of:
<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/EmployeeDirectory">
<Resource
name="jdbc/employeedirectory" auth="Container"
type="javax.sql.DataSource" username="EmployeeDir"
password="EmployeeDirectory" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://127.0.0.1:3306/EmployeeDirectory?autoReconnect=true"
maxActive="15" maxIdle="7"
validationQuery="Select 1" />
</Context>
a web.xml of:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- Omit Servlet Info -->
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/employeedirectory</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
and a hibernate.cfg.xml of:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.datasource">java:comp/env/jdbc/employeedirectory</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- Omit other Mappings -->
<mapping class="EmployeeDirectory.data.PhoneNumber" resource="EmployeeDirectory/data/PhoneNumber.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Now, I get a org.hibernate.HibernateException: Could not find datasource error.
Am I on the right path for moving from development to production? What am I missing?
I think you are on the right track. I would first set up the datasource and verify it out side of hibernate. Here is a good article on that: http://tomcat.apache.org/tomcat-6.0-doc/jndi-resources-howto.htm and some examples here: http://www.mbaworld.com/docs/jndi-datasource-examples-howto.html
Then, I would configure hibernate to use the datsource. From looking at your hibernate.cfg.xml file I think you should try changing hibernate.connection.datasource to jdbc/employeedirectory
the jndi datasource should be defined in /tomcat/server.xml see Tomcat JNDI Datasource how-to and not in webapp/context.xml
Tomcat 6 requires that you add the resource tag to the context.xml, not the server.xml. You could in Tomcat 5.x. I have it working fine in a separate install of Tomcat, but I'm still trying to use connection pooling inside NB 6.5.
That same Apache site has a link to the Tomcat 6 version of JNDI and it tells you to add the resource tag to the context.xml.