如下所示,我用jdbc来创建一个MySQL触发器,自己在navicat里面实验可以成功,但是程序跑起来就会提示创建触发器的语句有语法错误。求指教scaladefcreatTable(tbname:String):Unit={valconn:Connection=getConnif(conn!=null){valstmt:Statement=conn.createStatementvalctbsql:String="createtableifnotexists"+tbname+"("+"idbigint(20)notnullprimarykey,"+"namevarchar(255)notnull,"+"pricedouble,"+"pricechangetodaydouble,"+"categoryvarchar(20));"valtbtrigger="droptriggerifexists"+tbname+"pricechange"+"createtrigger"+tbname+"pricechangebeforeupdateon"+tbname+"foreachrow"+"begin"+"setnew.pricechangetoday=new.price-old.price;"+"end"stmt.execute(ctbsql)stmt.execute(tbtrigger)}}
阿晨1998
相关分类