Hello,
We at Tufan Infotech are evaluating Struts for using in our web application
development.
I am not able to connect to a Oracle 8i database and retrieve or update
data.  The datasource configuration in struts-config.xml is given below.

 <!-- ========== Data Source Configuration ===============================
-->

  <data-sources>
    <data-source
       autoCommit="false"
      description="Oracle Data Source Configuration"
      driverClass="oracle.jdbc.driver.OracleDriver"
         maxCount="4"
         minCount="2"
         password="pisdba123"
              url="jdbc:oracle:thin:@pavan:1521:navin"
             user="pisdba"
    />
  </data-sources>
<!--============================================================== -->

The code snippet which tried to connect is given below

Connection con = null;
PreparedStatement ps = null;
ResultSet rst = null;
javax.sql.DataSource dataSource = null;
String str = "insert into metadata values (?,?,?,?,?)";

String type=((MetadataForm)form).getType();
String code=((MetadataForm)form).getCode();
String description=((MetadataForm)form).getDescription();
String sequence=((MetadataForm)form).getSequence();
String isDefault=((MetadataForm)form).getIsDefault();

ActionErrors errors = new ActionErrors();

          try
          {
               dataSource = servlet.findDataSource(null);
               con = dataSource.getConnection();
               ps = con.prepareStatement(str);
               ps.setString(1,type);
               ps.setString(2,code);
               ps.setString(3,description);
               ps.setString(4,sequence);
               ps.setString(5,isDefault);
               ps.executeUpdate();
          }
          catch(Exception e)
          {
               errors.add(ActionErrors.GLOBAL_ERROR, new ActionError
("error.database.missing"));
          }
          finally
          {
               try
               {
                    con.close();
               }
               catch(Exception e)
               {
                    errors.add(ActionErrors.GLOBAL_ERROR, new ActionError
("error.database.missing"));
               }
          }


The above code is not updating the database.  It thows an exception and
shows the message in 'errors'.  One of the statements below seems to be
failing and gives a nullPointerException.

Would appreciate some inputs to solve the problem.  Also would appreciate
code snippets used to connect to datasources (example Oracle).

Best regards
Suresh

Reply via email to