You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Loren Hall <lo...@attbi.com> on 2002/12/31 06:59:25 UTC

RE: How to connect a database in SQL Server ? (NEWBIE)

Hi, trying to help my webhost get this working for mySQL.  Previously posted

> The datasource must be registered with the application server you are
using.

I've got tomcat and apache involved, what files do I need to make changes
to?  Is registering simply copy-pasting the data-source element from
struts-config to server.xml?


thanks,
Loren

-----Original Message-----
From: Jitendra Singh [mailto:jits_1998@hotmail.com]
Sent: Sunday, December 29, 2002 1:01 AM
To: Struts Users Mailing List
Subject: Re: How to connect a database in SQL Server ?


The datasource must be registered with the application server you are using.
First check if its done.

Jitendra
----- Original Message -----
From: "Tanmaya" <ta...@applabsindia.net>
To: <st...@jakarta.apache.org>
Sent: Friday, December 27, 2002 5:44 PM
Subject: How to connect a database in SQL Server ?


Hi All,

I am new to Struts.Kindly anyone let me know, what I should do, to connect a
database in SQL Server.I have the struts-config.xml file where I defined the
datasource parameters...

<data-sources>
    <data-source>
      <set-property property="autoCommit"
                             value="false"/>
       <set-property property="description"
                       value="Example Data Source Configuration"/>
      <set-property property="driverClass"

value="com.microsoft.jdbc.sqlserver.SQLServerDriver"/>
      <set-property property="maxCount"
                       value="4"/>
      <set-property property="minCount"
                       value="2"/>
      <set-property property="password"
                       value="taapplication"/>
      <set-property property="url"
                       value="jdbc:microsoft:sqlserver://tanmaya:1433"/>
      <set-property property="user"
                       value="taapplication"/>
    </data-source>
  </data-sources>

In the Action class,I tried to access the database in perform method as
follows...

public ActionForward perform(ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response) {

        Connection connection = null;
        DataSource dataSource = null;
        Statement statement = null;
        ResultSet resultSet = null;
        try {
            dataSource = servlet.findDataSource(null);
            connection = dataSource.getConnection();
                        statement = connection.createStatement();
            resultSet = statement.executeQuery("select * from team_shift");
            System.out.println("\n\n AFTER EXEcuting the query.....");
            while (resultSet.next())
            {

System.out.println("Shift:"+resultSet.getString("shift_code"));
            }
            resultSet.close(); // just a test
        } catch (SQLException sqle) {
            getServlet().log("Connection.process", sqle);
        } finally {

            try {
                connection.close();
            } catch (SQLException e) {
                getServlet().log("Connection.close", e);
            }
        }


In this way I am able to connect to the default database of SQL Server(i.e.
master) database successfully.I wanna access to my own database.How can I
achive it ??Where should I mention my database name ?? I tried by mentioning
my database name in the url property as follow :
set-property property="url"
value="jdbc:microsoft:sqlserver://tanmaya:1433/TAProd"/>

But in this way I am getting error (org.apache.jasper.JasperException:
Cannot find ActionMappings or ActionFormBeans collection) while tried to
access the jsp itself.

Please help me to knock this problem down.

Thanks in advance,
Tanmaya


--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>