1 Reply Latest reply on Aug 18, 2008 2:04 AM by taocore

    database issue

    taocore

      I am using my firebird database.
      I create desktop.fdb under jboss-portal-2.6.6.GA\server\default\data\desktop, and create desktop-firebird-ds.xml under the deploy directory with the content:

      <datasources>
       <local-tx-datasource>
       <jndi-name>DesktopDS</jndi-name>
       <connection-url>jdbc:firebirdsql:local:${jboss.server.data.dir}${/}desktop${/}desktop.fdb</connection-url>
       <driver-class>org.firebirdsql.jdbc.FBDriver</driver-class>
       <user-name>sysdba</user-name>
       <password><![CDATA[masterkey]]></password>
       </local-tx-datasource>
      </datasources>
      

      There is one table called computer_t with one record in desktop.fdb.
      I have also placed the jaybird-full-2.1.6.jar under ${jboss_home}/server/default/lib

      I changed the HelloWorldPortlet to show something in the database. The code is:
      protected void doView(RenderRequest rRequest, RenderResponse rResponse) throws PortletException, IOException, UnavailableException
       {
       rResponse.setContentType("text/html");
       PrintWriter writer = rResponse.getWriter();
       writer.write("Hello World!\n");
       Connection conn = null;
       try
       {
       DataSource ds = (DataSource) new InitialContext().lookup("java:/DesktopDS");
       System.out.println("1111111111111");
       conn = ds.getConnection();
       System.out.println("222222222222222");
       String sql = "select * from computer_t";
       PreparedStatement s = conn.prepareStatement(sql);
       System.out.println("3333333333333333");
       ResultSet rs = s.executeQuery();
       System.out.println("4444444444444444444");
       while (rs.next())
       {
       System.out.println("55555555555555555555");
       String name = rs.getString(2);
       writer.write(name + "\n");
       }
       } catch (NamingException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
       } catch (SQLException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
       }
       finally
       {
       if (conn != null)
       {
       try {
       conn.close();
       } catch (SQLException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
       }
       }
       }
       writer.close();
       }
      


      After deploying it and navigate the browser to the default page. I found no record shown in the portlet. The debug info was printed on the console 1, 2, 3, 4 but no 5.
      After shut down the server, I use isql connect to the desktop.fdb, and found the record inserted before was lost.
      It seems that the portal clear my table. Any suggestions?

        • 1. Re: database issue
          taocore

          Sorry, it is my mistake.
          Before quitting from isql, I did not commit, so the inserting recodes were not really written to the database.