Trying a database other than MySQL not going well

60 views
Skip to first unread message

farmer chet

unread,
Apr 22, 2013, 2:30:28 PM4/22/13
to web4j...@googlegroups.com
We want to use Web4J for an internal application.
When we do anything to the Electricity sample it stops working.

We need to use SQLServer. We have the jTDS driver and know how to make it work in Java, but it will not work with Web4J for us.

We created a DAO, an Action class, and all the other required classes for a view, but all we get is a message:
"oops, and error occurred".

It may be related to the driver configuration.
In the electricity.xml file was this Resource setting that we don't know what to change it to:
 <Resource
   name="jdbc/electricity"

What value should the name attribute be? Where in the code does this map to?

Also, in the default web.xml we saw this line and thought it may need to be changed:
    <init-param> 
      <param-name>DefaultDbConnectionString</param-name>
      <param-value>java:comp/env/jdbc/electricity</param-value>
    </init-param> 

But its unclear on what to change the param-value to.

Anyone have to change these properties to get a non-MySQL database to work?
Any suggestions on how to troubleshoot database problems?

Thanks for any assistance.

John O'Hanley

unread,
Apr 22, 2013, 6:40:43 PM4/22/13
to web4j-users
Hello,

When getting started, you need to work through the tutorial:
http://www.web4j.com/Tutorial.jsp

Since you are using SQLServer, any items that are specific to the
database will need to change. You are correct, you need to put your
database driver where Tomcat can see it.

In the electricity.xml file, you will need to change the indicated
settings:

<Context docBase="C:\Temp4\electricity" reloadable="true">
<Resource
name="jdbc/electricity" -- stays the same
auth="Container" -- stays the same
type="javax.sql.DataSource" -- stays the same
username="johanley" -- CHANGE this
password="********" -- CHANGE this
driverClassName="com.mysql.jdbc.Driver" -- CHANGE this
url="jdbc:mysql://localhost:3306/electricity?
useServerPrepStmts=false" -- CHANGE this
maxActive="10" -- stays the same
maxIdle="5" -- stays the same
/>
</Context>

If you are still having problems, let me know.

- John O'Hanley

John O'Hanley

unread,
Apr 22, 2013, 6:42:08 PM4/22/13
to web4j-users
The value

java:comp/env/jdbc/electricity

should remain the same in web.xml.

- John

John O'Hanley

unread,
Apr 22, 2013, 6:51:02 PM4/22/13
to web4j-users
You can also change the setting in web.xml named
ErrorCodeForDuplicateKey.

For SQLServer, a cursory google search indicates that the value should
be 2601.

You should also review this list of all items in web.xml, with respect
to *database* settings:
http://www.web4j.com/UserGuide.jsp#ConfiguringWebXml
Reply all
Reply to author
Forward
0 new messages