问题
I am facing one problem when am trying to insert values from flex(frontend) to database(backend).No problem in blazeds connection.I think problem is with java code.Anyway am pasting both java and flex code.Please let me know how to insert values into database.I am not well in java.So i tried a lot to solve this issue.
My Flex code is:
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.utils.ObjectUtil;
private function processSendFeedback():void
{
ro.getHelloByName(name_txt.text,email_txt.text,number_txt.text,fb_txt.text);
}
private function result(event:ResultEvent):void
{
Alert.show(ObjectUtil.toString(event.result));
}
private function fault(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="helloworldname"
result="result(event)"
fault="fault(event)"/>
</fx:Declarations>
<s:Panel x="176"
y="112"
width="414"
height="325"
title="FeedBack"
borderColor="#008040"
fontWeight="bold"
fontSize="13">
<s:Button label="Submit"
id="senfeddback"
click="processSendFeedback()"
x="178"
y="246"
height="22"
width="86"
cornerRadius="12"/>
<s:Label x="61" y="38" text="Name"/>
<s:Label x="61" y="72" text="Email"/>
<s:Label x="61" y="105" text="Number"/>
<s:Label x="50" y="142" text="Feedback"/>
<s:TextInput id="name_txt" x="119" y="30" width="260"/>
<s:TextInput id="email_txt" x="119" y="65" width="260"/>
<s:TextInput id="number_txt" x="119" y="100" width="260"/>
<s:TextInput id="fb_txt" x="119" y="134" width="260" height="104"/>
</s:Panel>
My Java Code is:
public class HelloWorldName
{
public static void main(String[] argv)
{
System.out.println("-------- PostgreSQL " +
"JDBC Connection Testing ----------");
getHelloByName(null, null, null, null);
}
public static String getHelloByName(String aName,String aMail,String aNumber,String aFeedback)
{
String host = "localhost";
String port = "1234";
String dbName = "test";
Connection connection = null;
try
{
connection = DriverManager.getConnection(
"jdbc:postgresql://" + host + ":" + port + "/" + dbName,"postgres", "admin");
System.out.println("Database is connected");
String strSQL = "insert into feedback(name,mobile_num,mail,feedback) values ('" + aName + "','" + aNumber +"','" + aMail +"','" + aFeedback +"')";
Statement st = connection.createStatement();
int a=st.executeUpdate(strSQL);
System.out.println("hi,query executed");
}
catch(Exception e)
{
System.out.println();
}
return "Hello from Java, " + aName + "," + aMail +"," + aNumber +"," + aFeedback +"";
}
}
I think i am sending null values in Main in java code.But if i try to add aName,aNumber,aMail,aFeedback in the place of null values error is showing.Is there any way to get solve this issue or is there any site to help to insert values into db using java,blazeds.Please help me.
Thanks in Advance.
回答1:
I think problem is JAVA static method according to Remoting Service definition
The Remoting Service lets a client application access the methods of server-side Java objects
and in java/oops static methods are not associated to Object/instance its depends-upon/associated to class
your method should be like this to accept call from flex
public String getHelloByName(String aName,String aMail,String aNumber,String aFeedback)
and to call it in main(java main) use following lines
HelloWorldName helloWorldName = new HelloWorldName();
helloWorldName.getHelloByName(null, null, null, null);
Here is Flash-Builder BlazeDS-Remoting sample
hopes that works
来源:https://stackoverflow.com/questions/6042076/passing-parameters-from-flex-to-database-using-java