mybaties使用#{}取不到数据

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/jaywee_chan/article/details/64904678

          最近使用mybaties做项目,在编写一个update语句时,老是更新不到数据。经过一步步分解,发现where条件中的#{columnName} 直接赋值替换时能更新到数据,发现问题在此。后来使用'${columnName}' 解决了该问题。MARK一下。

         最后百度发现原来是oracle数据库char字段问题,因为查询条件传入字段长度与数据库定义长度不匹配,故更新不到。也可以使用模糊查询的方式匹配到数据,比如like concat(#{userName},"%")的方式处理。



展开阅读全文

为什么取不到数据

05-12

数据库中的存储过程是rnALTER proc UTC_GetMingxiBaobiaorn(rn @UTC_MingXi_Cust varchar(50),rn @UTC_MingXi_State int,rn @UTC_MingXi_date varchar(20),rn @UTC_MingXi_Accuser varchar(30)rn)rnasrnselect h.UTCid,h.PhoneNo,h.CustCode,h.CustName,convert(varchar(10),h.Rectime,120) as Rectime,rn h.Flag,convert(varchar(10),h.Acctime,120) as Acctime,h.Accuser,d.ArtCode,d.Quantity,a.ArtName rnfrom utc_header as h join utc_detail as d rnon(h.UTCid = d.UTCid) join utc_article as arnon(d.artcode=a.artcode)rnwhere (@UTC_MingXi_Cust is null or CustCode = @UTC_MingXi_Cust) rn and (@UTC_MingXi_State=3 or Flag = @UTC_MingXi_State)rn and (@UTC_MingXi_date is null or @UTC_MingXi_date = convert(varchar(10),Acctime,120))rn and (@UTC_MingXi_Accuser ='ALL' or Accuser = @UTC_MingXi_Accuser)rnrnrnrnrnrnrn程序代码是rnprotected void Button1_Click(object sender, EventArgs e)rn rnrn SqlParameter[] workParam = new SqlParameter[4];rn workParam[0] = new SqlParameter("@UTC_MingXi_Cust", SqlDbType.NVarChar);rn workParam[0].Direction = ParameterDirection.Input;rn workParam[0].Value = "350944";rnrn workParam[1] = new SqlParameter("@UTC_MingXi_State", SqlDbType.Int);rn workParam[1].Direction = ParameterDirection.Input;rn workParam[1].Value = 3;rnrn workParam[2] = new SqlParameter("@UTC_MingXi_date", SqlDbType.NVarChar);rn workParam[2].Direction = ParameterDirection.Input;rn workParam[2].Value = "2009-05-07";rnrn workParam[3] = new SqlParameter("@UTC_MingXi_Accuser", SqlDbType.NVarChar);rn workParam[3].Direction = ParameterDirection.Input;rn workParam[3].Value = "萧山清点员";rnrn rn DataSet ds = new DataSet();rn DataBaseM DBM = new DataBaseM();rn ds = DBM.RunProc("UTC_GetMingxiBaobiao", workParam, ds); rnrn if (ds.Tables[0].Rows.Count == 0)// 执行这一句rn rn Response.Redirect("Nodata.aspx");rn rn ReportViewer1.Visible = true;rnrn ReportDataSource rds = new ReportDataSource("DataSetmingxi_UTC_GetMingxiBaobiao", ds.Tables[0]);rn ReportViewer1.LocalReport.DataSources.Clear();rn ReportViewer1.LocalReport.DataSources.Add(rds);rnrn ReportViewer1.LocalReport.Refresh();rnrnrnrn在查分器中执行rnexec UTC_GetMingxiBaobiao '35044',3,'2009-05-07','萧山清点员' 有数据返回rnrn 论坛

为什么OLEDBCommand取不到数据

08-23

我用VB.Net制作了一个搜索程序,但是有个问题,就是用程序去查询Access数据库总是查不到数据,但是断掉程序,然后把OLEDBCommand里面的CommandText属性中的SQL语句复制到Microsoft Access中的查询窗口里面执行就能查询到数据,这是怎么回事?数据库太大会造成这种现象吗?rn这是有关代码:rn[code=VB.NET]rnIf SearchIndex Then '如果选择了从数据库中搜索rn Dim cmdtext As String = "" '定义SQL语句变量rn If FSizeValue = FileSizeCode.Unlimited Then ‘如果选择“不限文件大小”rn Dim args() As String = fname, CreatonTime, ModifiedTime, extName ’参数rn If Not SearchFullPath Then ‘如果没选择“从文件路径中搜索”rn cmdtext = String.Format("SELECT * FROM [searchindex] WHERE index_filename like ""*0*"" AND index_ctime < #1# AND index_mtime < #2# AND index_extension like ""3*""", args) ’生成sqlrn Elsern cmdtext = String.Format("SELECT * FROM [searchindex] WHERE index_path like ""*0*"" AND index_ctime < #1# AND index_mtime < #2# AND index_extension like ""3*""", args)rn End Ifrn Elsern Dim fsize1 As Long, fsize2 As Long = -1rn Select Case FSizeValuern Case FileSizeCode.Bigrn fsize1 = 1 * 1024 * 1024 : fsize2 = 16 * 1024 * 1024rn Case FileSizeCode.Mediumrn fsize1 = 128 * 1024 : fsize2 = 1048576rn Case FileSizeCode.Smallrn fsize1 = 64 * 1024 : fsize2 = 128 * 1024rn Case FileSizeCode.Superrn fsize1 = 16 * 1024 * 1024 : fsize2 = 128 * 1024 * 1024rn Case FileSizeCode.Tinyrn fsize1 = 0 : fsize2 = 64 * 1024rn Case FileSizeCode.Emptyrn fsize1 = 0rn Case FileSizeCode.Hugern fsize1 = 128 * 1024 * 1024rn End Selectrn If fsize2 <> -1 Thenrn Dim args() As String = fname, CreatonTime, ModifiedTime, fsize1, fsize2, extNamern If SearchFullPath Thenrn cmdtext = String.Format("SELECT * FROM [searchindex] WHERE index_path like ""*0*"" AND index_ctime < #1# AND index_mtime < #2# AND index_size > 3 AND index_size <= 4 AND index_extension like ""5*""", args)rn Elsern cmdtext = String.Format("SELECT * FROM [searchindex] WHERE index_filename like ""*0*"" AND index_ctime < #1# AND index_mtime < #2# AND index_size > 3 AND index_size <= 4 AND index_extension like ""5*""", args)rn End Ifrn Elsern If fsize1 = 0 Thenrn Dim args() As String = fname, CreatonTime, ModifiedTime, fsize1, extNamern If SearchFullPath Thenrn cmdtext = String.Format("SELECT * FROM [searchindex] WHERE index_path like ""*0*"" AND index_ctime < #1# AND index_mtime < #2# AND index_size = 3 AND index_extension like ""4*""", args)rn Elsern cmdtext = String.Format("SELECT * FROM [searchindex] WHERE index_filename like ""*0*"" AND index_ctime < #1# AND index_mtime < #2# AND index_size = 3 AND index_extension like ""4*""", args)rn End Ifrn Elsern Dim args() As String = fname, CreatonTime, ModifiedTime, fsize1, fsize2, extNamern If SearchFullPath Thenrn cmdtext = String.Format("SELECT * FROM [searchindex] WHERE index_path like ""*0*"" AND index_ctime < #1# AND index_mtime < #2# AND index_size > 3 AND index_size <= 4 AND index_extension like ""5*""", args)rn Elsern cmdtext = String.Format("SELECT * FROM [searchindex] WHERE index_filename like ""*0*"" AND index_ctime < #1# AND index_mtime < #2# AND index_size > 3 AND index_size <= 4 AND index_extension like ""5*""", args)rn End Ifrn End Ifrn End Ifrn End Ifrn Dim cmd As New OleDbCommand(cmdtext, c.PConn)rn Dim dr As OleDbDataReader = cmd.ExecuteReader '这里读不到数据,但是数据库里确实有rn While dr.Readrn Dim lst As New ListViewItemrn lst.Text = dr("index_filename")rn lst.SubItems.Add(dr("index_path"))rn lst.SubItems.Add(dr("index_ctime"))rn lst.SubItems.Add(dr("index_mtime"))rn lst.SubItems.Add(dr("index_size"))rn lst.SubItems.Add(dr("index_extension"))rn list.Add(lst)rn End Whilern dr.Close()rn cmd.Dispose()rn[/code] 论坛

没有更多推荐了,返回首页