繁体   English   中英

如何将字符串转换为从html文本框接收的数组,然后将其传输到存储过程?

[英]How to convert a String to an Array received from a html text box and then transfer it to a stored procedure?

我在文本框中收到字符串(例如:“ Delhi,孟买,加尔各答”),然后将其发送到jsp页面,在该页面中我需要将其转换为Array,以便数组的第一个元素具有“ Delhi”,第二个具有“孟买”等等。 现在,我想将此数组发送到数据库处理程序页面,在该页面上,我有一个方法需要接收此字符串并使用此参数调用存储过程。 基本上,我不确定如何将字符串转换为数组,然后将其传递给存储过程。 任何帮助将不胜感激。 谢谢。

This is my jsp code:
String s_word= request.getParameter("Search_Word");
            session.setAttribute("ssword", s_word);
            String[] indnames = s_word.split(",");
//Here i don't know how to send indnames to the dbhandler page.
-----------------------------------------------------------------------
My method in dbhandler.java
public static ResultSet zz(String[] a) {
        ResultSet rs=null;
        try {

            Connection con = getConnection();
            CallableStatement ps = con.prepareCall("{call zz1(?,?)}");
            ps.setArray(1,a);
            ps.registerOutParameter(2, OracleTypes.CURSOR);
            ps.execute();

            rs = ((OracleCallableStatement) ps).getCursor(2);

        } catch (Exception e) {
        }
        return rs;
    }

存储过程需要接收数组。

采用

String cities[] = stringVariable.split("");

这会将具有多个城市的字符串转换为城市的字符串数组。

您可以将值传递给java类,如下所示,

<jsp:useBean id="sample" scope="page" class="com.mellon.sample" /> // sample is java file name  

//-------now pass parameter indnames to your sample java file here sample is the class name and function_name is the method name.

sample.function_name(indnames);

好吧,我知道了如何做。 在zz方法下的dbhandler.java页面中,我添加了:

Connection con = getConnection();
ArrayDescriptor arr= ArrayDescriptor.createDescriptor("ARRAY_COLLECTION",con);
//Here ARRAY_COLLECTION is my array type.
Array array= new ARRAY(arr,con,a);
//'a' is my String[] variable
Callable statement= con.prepareCall("{call zz1(?,?)}");
ps.setArray(1, array);
.
.
.
and so on.

暂无
暂无

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

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