XlsDataSetでNoSuchMethodErrorが発生したときの対処方法

Excelファイルを出力するJavaクラス

XLSExporter.java
package hoge;
 
import java.io.FileOutputStream;
 
import org.dbunit.database.DatabaseConnection;
import org.dbunit.dataset.IDataSet;
import org.dbunit.dataset.excel.XlsDataSet;
 
public class XLSExporter {
    public static void main(String[] args) throws Exception {
        DatabaseConnection con = new DatabaseConnection(ConnectionManager.getConnection());
        IDataSet dataset = con.createDataSet();
        XlsDataSet.write(dataset, new FileOutputStream("export.xls"));
    }
}

NoSuchMethodError

log4j:WARN No appenders could be found for logger (org.dbunit.database.DatabaseConnection).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.poi.hssf.usermodel.HSSFCell.setCellValue(Lorg/apache/poi/hssf/usermodel/HSSFRichTextString;)V
    at org.dbunit.dataset.excel.XlsDataSetWriter.write(XlsDataSetWriter.java:101)
    at org.dbunit.dataset.excel.XlsDataSet.write(XlsDataSet.java:93)
    at hoge.XLSExporter.main(XLSExporter.java:13)

Apache POIのバージョンで解決

3.2を境にsetCellValueメソッドが無くなってしまったことが原因
mavenのpom.xmlを修正

pom.xml(修正前)

    org.dbunit
    dbunit
    2.4.8


    org.apache.poi
    poi
    3.7

pom.xml(修正後)

    org.dbunit
    dbunit
    2.4.8


    org.apache.poi
    poi
    3.2-FINAL
    pom

GridViewのページングで1ページ分のデータを抽出する方法

GridViewのページングでAllowPagingをTrueにするだけだと全ページ分のデータをとっているので、データ量が多いページではパフォーマンスが悪化してしまう。
ASP.NET 3.5以上だとVirtualItemCountという便利なプロパティがあって楽にやれそう。
ASP.NET 2.0だとこれがないので、ObjectDataSourceを使って下記のように工夫必要がある。


GridViewのページング機能を有効にする

10行目のAllowPagingをTrueにし、ページングを有効にする。

Paging.aspx
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Paging.aspx.vb" Inherits="Paging" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Paging Test</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="MyGridView" runat="server" AllowPaging="True" >
        </asp:GridView>
    </div>
    </form>
</body>
</html>

GridViewのDataSourceへObjectDataSourceをセット

ObjectDataSourceを生成し、25から29行目でデータを抽出するクラス、メソッド、メソッドの引数名を設定する。
25行目で設定したオブジェクトを36行目で生成する。

Paging.aspx.vb
Imports System.Data
 
Partial Class Paging
    Inherits System.Web.UI.Page
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            BindGrid()
        End If
    End Sub
 
    Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles MyGridView.PageIndexChanging
        MyGridView.PageIndex = e.NewPageIndex
        BindGrid()
    End Sub
 
    Private Sub BindGrid()
        MyGridView.DataSource = CreateDataSource()
        MyGridView.DataBind()
    End Sub
 
    Private Function CreateDataSource() As ObjectDataSource
        Dim ods = New ObjectDataSource()
        ods.EnablePaging = MyGridView.AllowPaging
        ods.TypeName = "PagingService"
        ods.SelectMethod = "GetData"
        ods.SelectCountMethod = "GetDataCount"
        ods.StartRowIndexParameterName = "startRow"
        ods.MaximumRowsParameterName = "maxRows"
        ods.EnableViewState = False
        AddHandler ods.ObjectCreating, New ObjectDataSourceObjectEventHandler(AddressOf CreateDataObject)
        Return ods
    End Function
 
    Private Sub CreateDataObject(ByVal sender As Object, ByVal e As ObjectDataSourceEventArgs)
        e.ObjectInstance = New PagingService()
    End Sub
End Class

データ抽出ロジック(テスト実装)

バインド時にGetDataメソッドやGetDataCountメソッドが呼び出される。

GetDataメソッドは1ページに必要なデータを抽出して返す。
ObjectDataSourceから渡されるstartRow変数やmaxRows変数を抽出条件に利用できる。
MySQLではLIMITで、OracleではROWNUMやROW_NUMBERを条件に抽出できる。

GetDataCountメソッドは全件数をカウントして返す。

PagingService.vb
Imports Microsoft.VisualBasic
Imports System.Data
 
Public Class PagingService
 
    Public Function GetData(ByVal startRow As Integer, ByVal maxRows As Integer) As DataTable
        Dim dt As DataTable = New DataTable()
        Dim dr As DataRow
        dt.Columns.Add(New DataColumn("IntegerValue", GetType(Int32)))
        dt.Columns.Add(New DataColumn("StringValue", GetType(String)))
        dt.Columns.Add(New DataColumn("DateTimeValue", GetType(String)))
        dt.Columns.Add(New DataColumn("BoolValue", GetType(Boolean)))
        Dim i As Integer
        For i = startRow To ((startRow + maxRows) - 1)
            dr = dt.NewRow()
            dr(0) = i
            dr(1) = "Item " & i.ToString()
            dr(2) = DateTime.Now.ToShortDateString()
            If (i Mod 2 <> 0) Then
                dr(3) = True
            Else
                dr(3) = False
            End If
            dt.Rows.Add(dr)
        Next i
        Return dt
    End Function
 
    Public Function GetDataCount() As Integer
        Return 1000
    End Function
End Class

CodeIgniterをfluxflex環境で利用するときの.htaccess設定方法(2回目)

いろいろ試行錯誤した結果、今はこの設定にしています。


application/config/config.php
/*
|--------------------------------------------------------------------------
| URI PROTOCOL
|--------------------------------------------------------------------------
|
| This item determines which server global should be used to retrieve the
| URI string.  The default setting of 'AUTO' works for most servers.
| If your links do not seem to work, try one of the other delicious flavors:
|
| 'AUTO'			Default - auto detects
| 'PATH_INFO'		Uses the PATH_INFO
| 'QUERY_STRING'	Uses the QUERY_STRING
| 'REQUEST_URI'		Uses the REQUEST_URI
| 'ORIG_PATH_INFO'	Uses the ORIG_PATH_INFO
|
*/
$config['uri_protocol']	= 'REQUEST_URI';
.htaccess
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php?/$1 [QSA,L]

QSAについてはmod_rewrite - QSAフラグが参考になりました。

fluxflexでInternal Server Errorが表示されたときの対処方法

10月1日の午前中からエラーが表示されるようになってて、Deployしたら復旧しました。
障害が多いけど日本人が起業したPaaSということで応援したい。

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, system@fluxflex.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Deployの手順

  1. Dashboardからプロジェクトを開く。
  2. 右上のDeployボタンをクリック。
  3. 「Request to clear repository and setup.」をチェックしてDEPLOYボタンをクリック。

git pullでエラー

git pullしたときのエラー

Enter passphrase for key '/c/Documents and Settings/*****/.ssh/id_rsa':
You asked me to pull without telling me which branch you
want to merge with, and 'branch.master.merge' in
your configuration file does not tell me, either. Please
specify which branch you want to use on the command line and
try again (e.g. 'git pull  ').
See git-pull(1) for details.

If you often merge with the same branch, you may want to
use something like the following in your configuration file:
    [branch "master"]
    remote = 
    merge = 

    [remote ""]
    url = 
    fetch = 

See git-config(1) for details.

解決策

$ git config branch.master.merge refs/heads/master
$ git config branch.master.remote origin
最新記事
カテゴリ
スポンサード
スポンサード
月別アーカイブ
RSSリンクの表示
QRコード
QR