用android文本视图绑定sql存储过程值

时间:2016-11-08 06:52:40

标签: java android sql

使用Android应用程序项目,数据库是sql server 2008,我写了一个sql程序,

USE [master]
GO
/****** Object:  StoredProcedure [dbo].[getSalesIdtest]    Script Date: 11/08/2016 12:46:00 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[getSalesIdtest]
as
(
select LIDTagp,LIDLen,CurrentNO,LIDTagS,LCompanyID from dbo.SetupListIDC WHERE LIDType = 'slsSalesOrder' AND LCompanyID = '01'
)
UPDATE SetupListIDC SET CurrentNo = CurrentNo + 1 WHERE LIDType = 'slsSalesOrder' AND LCompanyID = '01'

sql程序名是getSalesidtest,用android textview绑定返回值,为此我正在尝试

 public void gendata(View view) {
    if (view.getId() == R.id.gen) {

                connect = connectionclass(un, pass, db, ip);

                PreparedStatement statement = null;
                try {
                    statement = connect.prepareStatement("EXEC dbo.getSalesIdtest");
                } catch (SQLException e) {
                    Log.e("Error 1 here: ", e.getMessage());
                }

                try {
                    rs = statement.executeQuery();
                } catch (SQLException ex) {
                    Log.e("error 2 here: ", ex.getMessage());
                }
                try {
                    while (rs.next()) {

                        TextView generateData = (TextView) findViewById(R.id.genData);
                        generateData.setText(rs.getString(1));
                    }
                } catch (SQLException e) {
                    Log.e("Error 3 here: ", e.getMessage());
                }
    }
}

我希望将值(从sql过程返回)与按钮单击的文本值绑定,按钮名称为gen并添加一个onclick方法,即gendata。日志没有错误。

0 个答案:

没有答案