使用jdbc创建MySQL的trigger出现错误
如下所示,我用jdbc来创建一个MySQL触发器,自己在navicat里面实验可以成功,但是程序跑起来就会提示创建触发器的语句有语法错误。求指教
scala
def creatTable(tbname:String): Unit = { val conn: Connection = getConn if (conn != null) { val stmt: Statement = conn.createStatement val ctbsql: String = "create table if not exists " + tbname + "(" + "id bigint(20) not null primary key," + "name varchar(255) not null," + "price double," + "pricechangetoday double," + "category varchar(20));" val tbtrigger = "drop trigger if exists "+tbname+"pricechange" + " create trigger "+tbname+"pricechange before update on " + tbname + " for each row" + " begin" + " set new.pricechangetoday=new.price-old.price;" + " end " stmt.execute(ctbsql) stmt.execute(tbtrigger) } }
唵叭呢唻哄
10 years, 2 months ago