我已经通过与 mySQL DB 的连接实现了 SpringFlex 1.5,它最初可以工作并检索数据,但是当我输入一个在我的表中不存在的无效数据时,应用程序似乎冻结了,之后甚至无法输入有效数据,并且我需要停止并再次启动 Tomcat 以使其再次工作
应用程序上下文.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&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;
}
定义的 Getter 和 Setter
@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; }