使用java将参数从flex传递到数据库 [英] Passing Parameters from flex to database using java

查看:19
本文介绍了使用java将参数从flex传递到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试将值从 flex(前端)插入到数据库(后端)时,我遇到了一个问题.blazeds 连接没有问题.我认为问题在于 java 代码.无论如何我正在粘贴 java 和 flex 代码.请让我知道如何将值插入到数据库中.我在 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 代码是:

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>

我的 Java 代码是:

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 +"";
}
}

我想我在 java 代码的 Main 中发送空值.但是如果我尝试在空值的位置添加一个名称、一个编号、一个邮件、一个反馈,则会显示错误.有没有办法解决这个问题,或者是有任何网站可以帮助使用 java,blazeds 将值插入 db.请帮助我.

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 static 方法根据 远程服务定义

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/oops中静态方法关联到对象/instance它的依赖/关联到类

and in java/oops static methods are not associated to Object/instance its depends-upon/associated to class

你的方法应该是这样接受来自flex的调用

your method should be like this to accept call from flex

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

并在 main(java main) 中调用它,使用以下几行

and to call it in main(java main) use following lines

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

这是 Flash-Builder BlazeDS-Remoting 示例

Here is Flash-Builder BlazeDS-Remoting sample

希望有效

这篇关于使用java将参数从flex传递到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆