大海话语 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日

悬赏问题

  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)