0

私はMySQLDBに接続してSpringFlex1.5を実装しましたが、最初は機能してデータを取得しますが、テーブルに存在しない無効なデータを入力すると、アプリケーションがフリーズし、その後は有効なデータを入力しなくても機能します。 Tomcatを再び動作させるには、Tomcatを停止して再起動する必要があります

applicationContext.xml

<bean id="authToLeaveService" class="com.model.atl.AuthToLeaveServiceImpl">
    <constructor-arg ref="dataSource" />        
</bean>

<bean id="dataSource" 
     class="org.apache.commons.dbcp.BasicDataSource">

    <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    <property name="url" value="jdbc:mysql://dxfcm:3306/wookie?autoReconnect=true&amp;zeroDateTimeBehavior=convertToNull"/>
    <property name="username" value="darth" />
    <property name="password" value="vader" />
    <property name="validationQuery" value="SELECT 1"/>
</bean>

私の見解

<fx:Declarations>       
    <s:ChannelSet id="cs">
        <s:AMFChannel url="http://localhost:8400/flexspring/messagebroker/amf"/>
    </s:ChannelSet>     
    <s:RemoteObject id="atlRO" channelSet="{cs}" destination="authToLeaveService"/> 
</fx:Declarations>


[Bindable]
private var job:AtlJob;

private function onEnter(event:FlexEvent):void
{
    var token:AsyncToken = atlRO.findByBarcode(this.txtBarcode.text);
    token.addResponder(new AsyncResponder(onResult, onFault));
} 

private function onResult(event:ResultEvent, token:Object):void
{ job = event.result as AtlJob; }

private function onFault(event:FaultEvent, token:Object):void
{ }


<s:TextInput id="txtBarcode" x="23" y="60" width="218"
    enter="onEnter(event)" maxChars="16"/>

AltJob.as

[Bindable]
[RemoteClass (alias="com.model.atl.AtlJob")]
public class AtlJob
{
public var barcode:String;
public var pieces:int;
public var customerName:String;
}

AtlJob.javaパッケージcom.model.atl;

パブリッククラスAtlJobはjava.io.Serializable{を実装します

private static final long serialVersionUID = 1L;

private String barcode;
private String customerName;
private int pieces;

public AtlJob() {   }

public AtlJob(String barcode, int pieces, String customerName) {
    this.barcode = barcode;

    this.customerName = customerName;
    this.pieces= pieces;
}

ゲッターとセッターの定義

@Service("authToLeaveService")
@RemotingDestination(channels = { "my-amf", "my-secure-amf" })
public class AuthToLeaveServiceImpl implements AuthToLeaveService {

private final DataSource dataSource;

public AuthToLeaveServiceImpl(DataSource dataSource) {
    this.dataSource = dataSource; }

@RemotingInclude
public AtlJob findByBarcode(String barcode) {
AtlJob job = new AtlJob();
Connection con = null;

final String sql = "SELECT * FROM atl_job WHERE card_barcode = ?";

try {
    con = this.dataSource.getConnection();
    PreparedStatement ps = con.prepareStatement(sql);
    ps.setString(1, barcode);
    ResultSet rs = ps.executeQuery();

if (rs.next()) {
    job.setBarcode(rs.getString("barcode"));
    job.setPieces(rs.getInt("pieces"));
    job.setCustomerName(rs.getString("customerName"));}
} catch (SQLException e) {
    e.printStackTrace();
throw new RuntimeException(e);
} finally {
if (con!=null) {try { con.close();
} catch (SQLException e) {
e.printStackTrace();
} }} return job; }
4

1 に答える 1

0

ここのようにレコードが見つからない場合、例外はスローされません

...
if (rs.next()) {
  job.setBarcode(rs.getString("barcode"));
  job.setPieces(rs.getInt("pieces"));
  job.setCustomerName(rs.getString("customerName"));
}
// Put an else clause here and throw exception
else
{
  throw new Exception("Record Not found"); 
}

faultMethod でキャッチされた例外を表示してみてください..

 private function onFault(event:FaultEvent, token:Object):void   
 { 
    //Handle Fault event here Put some Alert here
 }
于 2012-07-06T09:38:02.237 に答える