大海话语 2021-12-16 22:12 采纳率: 87.6%
浏览 46
已结题

ql语句 当前时间,为now 报错

我在写sql语句时,加入了一个时间为当前,但是就是用now() ,为什么报 下面这样的错误呢?

### Error updating database.  Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'out_trade_no ) 
          values ( now()
            
            
             ' at line 1
### The error may involve com.hnsaturn.saturn005.dao.PayDao.addGOrder-Inline
### The error occurred while setting parameters
### SQL: ( out_trade_no )            values ( now()                                           ? )
### Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'out_trade_no ) 
          values ( now()
            
            
             ' at line 1
; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'out_trade_no ) 
          values ( now()
            
            
             ' at line 1] with root cause

java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'out_trade_no ) 
          values ( now()
            


java代码

GOrder gOrder = new GOrder();
        gOrder.setOutTradeNo(orderString);
        payDao.addGOrder(gOrder);

实体类

@Data
@Builder
@EntityScan
public class GOrder implements Serializable {
    public int id,gNumber;//订单Id、商品号
    //商品号、商户订单号、支付宝交易号、支付金额、支付时间
    public String gName,price,outTradeNo,tradeNo,totalAmount,gmtPayment;
    private Integer uId,tradeStatus;//用户Id、交易状态(0未支付1已支付)
    private Date oTime;//订单提交时间

    @Tolerate
    public GOrder(){}
}

下面是sql 语句

<!--存入支付宝订单信息-->
    <insert id="addGOrder" parameterType="隐藏路径了.GOrder">
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null and id !=''" >
                id,
            </if>
            <if test="gName != null and gName !=''">
                g_name,
            </if>
            <if test="gNumber != null and gNumber !=''">
                g_number,
            </if>
            <if test="price != null and price !=''">
                price,
            </if>
            <if test="oTime != null and oTime !=''">
                o_time,
            </if>
            <if test="uId != null and uId !=''">
                u_id,
            </if>
            <if test="outTradeNo != null and outTradeNo !=''">
                out_trade_no,
            </if>
            <if test="tradeNo != null and tradeNo !=''">
                trade_no,
            </if>
            <if test="totalAmount != null and totalAmount !=''">
                total_amout,
            </if>
            <if test="gmtPayment != null and gmtPayment !=''">
                gmt_payment,
            </if>
            <if test="tradeStatus != null and tradeStatus !=''">
                trade_status,
            </if>
        </trim>
        <trim prefix=" values (" suffix=")" suffixOverrides=",">
            <if test="id != null and id !=''">
                #{id},
            </if>
            <if test="gName != null and gName !=''">
                #{gName},
            </if>
            <if test="gNumber != null and gNumber !=''">
                #{gNumber},
            </if>
            <if test="price != null and price !=''">
                #{price},
            </if>
            now(),
            <if test="uId != null and uId !=''">
                #{uId},
            </if>
            <if test="outTradeNo != null and outTradeNo !=''">
                #{outTradeNo},
            </if>
            <if test="tradeNo != null and tradeNo !=''">
                #{tradeNo},
            </if>
            <if test="totalAmount != null and totalAmount !=''">
                #{totalAmount},
            </if>
            <if test="gmtPayment != null and gmtPayment !=''">
                #{gmtPayment},
            </if>
            <if test="tradeStatus != null and tradeStatus !=''">
                #{tradeStatus},
            </if>
        </trim>

    </insert>


  • 写回答

1条回答 默认 最新

  • 你的意义 2021-12-16 22:35
    关注

    不是太懂你的sql语句思路,但是你这种问题属于sql语法问题,主要出现在now()哪里,这种情况你就围绕那个地方修改尝试就行,比较好解决,你可以自己尝试解决一下

    你可以把你想要写的sql语句先在自己的sql工具上写出来调试一下,如果有问题,可以先一点一点的添加sql语句功能,从基础的开始,直到添加到你的sql有问题,就可以直到问题出在哪里,之后调试好再组织语言写到xml里面。

    希望能给你一些思路

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 12月24日
  • 已采纳回答 12月16日
  • 创建了问题 12月16日

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程