NutzCN Logo
问答 H2数据库建表报错无法建表
发布于 2775天前 作者 qq_2a1c6850 4645 次浏览 复制 上一个帖子 下一个帖子
标签:
@Table("{t_task_${tname}}")
public class TTaskModel {
	@Id(auto=true)
	@Column("id")
	@Comment("ID")
	@ColDefine(type = ColType.INT, width = 20)
	private long id;
	@Column("request_id")
	@Comment("需求id")
	@ColDefine(type = ColType.INT, width = 20)
	private long request_id;
	@Column("website")
	@Comment("项目编码")
	@ColDefine(type = ColType.VARCHAR, width = 128)
	private String website;
	@Column("website")
	@Comment("项目编码")
	@ColDefine(type = ColType.VARCHAR, width = 128)
	private String project_code;
	@Column("down_type")
	@Comment("下载类型")
	@ColDefine(type = ColType.VARCHAR, width = 128)
	private String down_type;
	@Column("parm_type")
	@Comment("参数")
	@ColDefine(type = ColType.VARCHAR, width = 32)
	private String parm_type;
	@Column("content")
	@Comment("下载内容")
	@ColDefine(type = ColType.VARCHAR, width = 255)
	private String content;
	@Column("create_date")
	@Comment("创建日期")
	@ColDefine(type = ColType.DATE)
	private Date create_date;
	@Column("status")
	@Comment("状态")
	@ColDefine(type = ColType.INT, width = 2)
	private int status;

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public long getRequest_id() {
		return request_id;
	}

	public void setRequest_id(long request_id) {
		this.request_id = request_id;
	}

	public String getProject_code() {
		return project_code;
	}

	public void setProject_code(String project_code) {
		this.project_code = project_code;
	}

	public String getDown_type() {
		return down_type;
	}

	public void setDown_type(String down_type) {
		this.down_type = down_type;
	}

	public String getParm_type() {
		return parm_type;
	}

	public void setParm_type(String parm_type) {
		this.parm_type = parm_type;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public Date getCreate_date() {
		return create_date;
	}

	public void setCreate_date(Date create_date) {
		this.create_date = create_date;
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public String getWebsite() {
		return website;
	}

	public void setWebsite(String website) {
		this.website = website;
	}

}


TTaskModel task = new TTaskModel();
		task.setContent("http://club.autohome.com.cn/bbs/forum-c-3363-1.html");
		task.setDown_type("get_bbs_autohome");
		task.setProject_code("bbs");
		task.setWebsite("autohome");
		task.setCreate_date(new Date());
		task.setRequest_id(20170418);
		task.setStatus(1);
		task.setParm_type("forum-list");
		Dao dao = H2DataSource.getH2Dao();
		TableName.set(task.getWebsite());
		dao.exists(TTaskModel.class);
	
		dao.create(TTaskModel.class, true);
		TableName.clear();





下面是报的异常

Exception in thread "main" org.nutz.dao.DaoException: !Nutz SQL Error: 'CREATE TABLE {t_task_autohome}(
id SERIAL,
request_id NUMERIC(20),
website VARCHAR(128),
website VARCHAR(128),
down_type VARCHAR(128),
parm_type VARCHAR(32),
content VARCHAR(255),
create_date DATE,
status NUMERIC(2),
CONSTRAINT {t_task_autohome}_pkey PRIMARY KEY (id)
)'
PreparedStatement: 
'CREATE TABLE {t_task_autohome}(
id SERIAL,
request_id NUMERIC(20),
website VARCHAR(128),
website VARCHAR(128),
down_type VARCHAR(128),
parm_type VARCHAR(32),
content VARCHAR(255),
create_date DATE,
status NUMERIC(2),
CONSTRAINT {t_task_autohome}_pkey PRIMARY KEY (id)
)'
CaseMessage=Syntax error in SQL statement "CREATE TABLE {t_task_autohome}(
id SERIAL,
request_id NUMERIC(20),
website VARCHAR(128),
website VARCHAR(128),
down_type VARCHAR(128),
parm_type VARCHAR(32),
content VARCHAR(255),
create_date DATE,
status NUMERIC(2),
CONSTRAINT {t_task_autohome}_pkey PRIMARY KEY (id)
[*])" [42000-194]
	at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:96)
	at org.nutz.dao.impl.DaoSupport$DaoExec.invoke(DaoSupport.java:316)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:59)
	at org.nutz.dao.impl.DaoSupport.run(DaoSupport.java:239)
	at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:271)
	at org.nutz.dao.impl.DaoSupport.execute(DaoSupport.java:235)
	at org.nutz.dao.impl.NutDao.execute(NutDao.java:983)
	at org.nutz.dao.impl.jdbc.psql.PsqlJdbcExpert.createEntity(PsqlJdbcExpert.java:100)
	at org.nutz.dao.impl.EntityHolder.reloadEntity(EntityHolder.java:85)
	at org.nutz.dao.impl.NutDao.create(NutDao.java:784)
	at com.bds.node.server.App.main(App.java:33)
Caused by: org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement "CREATE TABLE {t_task_autohome}(
id SERIAL,
request_id NUMERIC(20),
website VARCHAR(128),
website VARCHAR(128),
down_type VARCHAR(128),
parm_type VARCHAR(32),
content VARCHAR(255),
create_date DATE,
status NUMERIC(2),
CONSTRAINT {t_task_autohome}_pkey PRIMARY KEY (id)
[*])" [42000-194]
	at org.h2.message.DbException.getJdbcSQLException(DbException.java:345)
	at org.h2.message.DbException.get(DbException.java:179)
	at org.h2.message.DbException.get(DbException.java:155)
	at org.h2.message.DbException.getSyntaxError(DbException.java:191)
	at org.h2.jdbc.JdbcConnection.translateSQL(JdbcConnection.java:1402)
	at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:169)
	at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:158)
	at org.apache.commons.dbcp.DelegatingStatement.execute(DelegatingStatement.java:264)
	at org.apache.commons.dbcp.DelegatingStatement.execute(DelegatingStatement.java:264)
	at org.nutz.dao.impl.sql.run.NutDaoExecutor._runStatement(NutDaoExecutor.java:321)
	at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:52)
	... 10 more
1 回复

为啥给表名包个大括号???

@Table("{t_task_${tname}}")
添加回复
请先登陆
回到顶部