我的名字是Rahul.I是flex的新手。我正在嘗試使用java將flex與blazeds集成。根據我的知識,我寫了一些代碼。但它沒有連接到數據庫。我貼我的代碼here.Please一下,並讓我知道,如果我做了那邊的任何錯誤:Flex與使用java的Blazeds集成的問題
我的Flex代碼:
<fx:Script>
<![CDATA[
import com.hello.vo.FeedbackVO;
import mx.controls.Alert;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.utils.ObjectUtil;
public function insertData():void
{
var feedbackvo:FeedbackVO = new FeedbackVO();
feedbackvo.name = input_name.text;
feedbackvo.number = input_number.text;
feedbackvo.email = input_email.text;
feedbackvo.feedback = input_feedback.text;
ro.insertData(feedbackvo);
}
public function onResult(event:ResultEvent):void
{
Alert.show(ObjectUtil.toString(event.result));
}
public function onFault(event:FaultEvent):void
{
Alert.show(ObjectUtil.toString(event.fault));
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
<s:RemoteObject id="ro"
destination="feedback"
source="com.hello.Feedback"
endpoint="http://localhost:8082/Feedback/messagebroker/amf">
<s:method name="insertData"
result="onResult(event)"
fault="onFault(event)"/>
</s:RemoteObject>
</fx:Declarations>
<s:BorderContainer x="0"
y="0"
width="100%"
height="100%">
<s:Panel width="364"
height="333" x="206" y="83">
<mx:Form x="0"
y="0"
width="100%"
height="100%">
<mx:FormItem label="Name:">
<s:TextInput id="input_name" width="249"/>
</mx:FormItem>
<mx:FormItem label="Number:">
<s:TextInput id="input_number" width="249"/>
</mx:FormItem>
<mx:FormItem label="Email:">
<s:TextInput id="input_email" width="248"/>
</mx:FormItem>
<mx:FormItem label="Feedback:">
<s:TextInput id="input_feedback" width="248" height="143"/>
</mx:FormItem>
<mx:FormItem>
<s:Button id="insert_btn"
label="Insert Data"
click="insertData();"/>
</mx:FormItem>
</mx:Form>
</s:Panel>
</s:BorderContainer>
我的Java代碼:
FeedbackVO.java :
package com.hello.vo;
public class FeedbackVO
{
private String name;
private String number;
private String email;
private String feedback;
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public String getNumber()
{
return number;
}
public void setNumber(String number)
{
this.number = number;
}
public String getEmail()
{
return email;
}
public void setEmail(String email)
{
this.email = email;
}
public String getFeedback()
{
return feedback;
}
public void setFeedback(String feedback)
{
this.feedback = feedback;
}
}
Feedback.java:
package com.hello;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import com.hello.vo.FeedbackVO;
public class Feedback
{
Connection connection;
Statement stmt;
ResultSet rs;
public Feedback()
{
String host = "localhost";
String port = "5432";
String dbName = "test";
Connection connection = null;
try
{
connection = DriverManager.getConnection(
"jdbc:postgresql://" + host + ":" + port + "/" + dbName,"postgres", "admin");
System.out.println("Database is connected");
stmt = connection.createStatement();
}
catch (Exception e)
{
e.printStackTrace();
}
}
public String insertData(FeedbackVO feedbackvo)
{
try
{
stmt = connection.createStatement();
String sql = "INSERT into feedback(name,number,email,feedback) VALUES ('" + feedbackvo.getName() + "','" + feedbackvo.getNumber() + "','" + feedbackvo.getEmail() + "','" + feedbackvo.getFeedback() +"')";
if(stmt.execute(sql))
{
return "Thanks For your Valuable Feedback";
}
}
catch (Exception e)
{
e.printStackTrace();
}
return "Sorry Your feedback is not entered";
}
}
如果我嘗試執行Feedback.mxml,那麼我會收到「抱歉,您的反饋未輸入」作爲輸出。我不知道問題在哪裏。我認爲flex已成功連接,但問題出在java code.If任何人得到一個想法,請幫助我。
非常感謝, 拉胡爾
嗨飛濺,我在FLEX和JAVA全新的。我需要創建一個集成FLEX和JAVA的應用程序。我想知道它是如何可能的。哪些是必需的軟件?請儘早回覆我。我非常渴望學習這個東西。 – 2012-02-03 05:03:17
@SagarRawal:使用「flex java」在Google上進行搜索應該引導您訪問http://www.adobe.com/devnet/flex/flex_java.html,這是一個非常好的Flex/Java開發資源彙編。 – splash 2012-02-07 10:04:01
感謝飛濺..非常感謝。 – 2012-02-08 12:18:17