简体   繁体   English

使用Java将参数从Flex传递到数据库

[英]Passing Parameters from flex to database using java

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. 我试图将值从flex(frontend)插入数据库(后端)时遇到一个问题.blazeds连接没问题。我认为java代码有问题。无论如何都要粘贴java和flex代码。请让我知道如何将值插入数据库中。我在java中不太好。所以我做了很多尝试来解决此问题。

My Flex code is: 我的Flex代码是:

<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: 我的Java代码是:

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. 我认为我正在用Java代码在Main中发送空值。但是如果我尝试在空值的位置添加aName,aNumber,aMail,aFeedback,则会显示错误。是否有任何方法可以解决此问题或是否有任何站点帮助使用Java,blazeds将值插入db。请帮助我。

Thanks in Advance. 提前致谢。

I think problem is JAVA static method according to Remoting Service definition 我认为问题是根据远程服务定义的JAVA静态方法

The Remoting Service lets a client application access the methods of server-side Java objects 远程服务使客户端应用程序可以访问服务器端Java对象的方法

and in java /oops static methods are not associated to Object /instance its depends-upon/associated to class java / oops中, 静态方法Object / instance关联,其依赖于/与class关联

your method should be like this to accept call from flex 您的方法应像这样接受来自flex的调用

public String getHelloByName(String aName,String aMail,String aNumber,String aFeedback)

and to call it in main(java main) use following lines 并在main(java main)中调用它,使用以下几行

HelloWorldName helloWorldName = new HelloWorldName();
helloWorldName.getHelloByName(null, null, null, null);

Here is Flash-Builder BlazeDS-Remoting sample 这是Flash-Builder BlazeDS-Remoting 示例

hopes that works 希望能奏效

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM