NutzCN Logo
问答 初始化默认跟用户不创建表(t_user),需要手动创建么
发布于 2470天前 作者 baby-pw 1569 次浏览 复制 上一个帖子 下一个帖子
标签:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'mysql.t_user' doesn't exist
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_161]
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[?:1.8.0_161]
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:1.8.0_161]
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[?:1.8.0_161]
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:425) ~[mysql-connector-java-5.1.44.jar:5.1.44]
	at com.mysql.jdbc.Util.getInstance(Util.java:408) ~[mysql-connector-java-5.1.44.jar:5.1.44]
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:943) ~[mysql-connector-java-5.1.44.jar:5.1.44]
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3973) ~[mysql-connector-java-5.1.44.jar:5.1.44]
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3909) ~[mysql-connector-java-5.1.44.jar:5.1.44]
	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2527) ~[mysql-connector-java-5.1.44.jar:5.1.44]
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2680) ~[mysql-connector-java-5.1.44.jar:5.1.44]
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2483) ~[mysql-connector-java-5.1.44.jar:5.1.44]
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2441) ~[mysql-connector-java-5.1.44.jar:5.1.44]
	at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1381) ~[mysql-connector-java-5.1.44.jar:5.1.44]
	at com.alibaba.druid.filter.FilterChainImpl.statement_executeQuery(FilterChainImpl.java:2473) ~[druid-1.1.5.jar:1.1.5]
	at com.alibaba.druid.filter.FilterAdapter.statement_executeQuery(FilterAdapter.java:2503) ~[druid-1.1.5.jar:1.1.5]
	at com.alibaba.druid.filter.FilterEventAdapter.statement_executeQuery(FilterEventAdapter.java:302) ~[druid-1.1.5.jar:1.1.5]
	at com.alibaba.druid.filter.FilterChainImpl.statement_executeQuery(FilterChainImpl.java:2470) ~[druid-1.1.5.jar:1.1.5]
	at com.alibaba.druid.proxy.jdbc.StatementProxyImpl.executeQuery(StatementProxyImpl.java:221) ~[druid-1.1.5.jar:1.1.5]
	at com.alibaba.druid.pool.DruidPooledStatement.executeQuery(DruidPooledStatement.java:217) ~[druid-1.1.5.jar:1.1.5]
	at org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:246) ~[nutz-1.r.65.jar:1.r.65]
	at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:53) ~[nutz-1.r.65.jar:1.r.65]
	at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:66) ~[nutz-1.r.65.jar:1.r.65]
	at org.nutz.dao.impl.interceptor.DaoLogInterceptor.filter(DaoLogInterceptor.java:22) ~[nutz-1.r.65.jar:1.r.65]
	at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:64) ~[nutz-1.r.65.jar:1.r.65]
	at org.nutz.dao.DaoInterceptorChain.invoke(DaoInterceptorChain.java:139) ~[nutz-1.r.65.jar:1.r.65]
	at org.nutz.dao.impl.sql.run.NutDaoRunner.runCallback(NutDaoRunner.java:159) ~[nutz-1.r.65.jar:1.r.65]
	at org.nutz.dao.impl.sql.run.NutDaoRunner._runWithoutTransaction(NutDaoRunner.java:126) ~[nutz-1.r.65.jar:1.r.65]
	at org.nutz.dao.impl.sql.run.NutDaoRunner._run(NutDaoRunner.java:93) ~[nutz-1.r.65.jar:1.r.65]
	at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:82) ~[nutz-1.r.65.jar:1.r.65]
	at org.nutz.dao.impl.DaoSupport.run(DaoSupport.java:240) ~[nutz-1.r.65.jar:1.r.65]
	at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:252) ~[nutz-1.r.65.jar:1.r.65]
	at org.nutz.dao.impl.NutDao.func(NutDao.java:761) ~[nutz-1.r.65.jar:1.r.65]
	at org.nutz.dao.impl.NutDao.func(NutDao.java:742) ~[nutz-1.r.65.jar:1.r.65]
	at org.nutz.dao.impl.NutDao._count(NutDao.java:729) ~[nutz-1.r.65.jar:1.r.65]
	at org.nutz.dao.impl.NutDao.count(NutDao.java:692) ~[nutz-1.r.65.jar:1.r.65]
	at com.ink.main.services.MainSetup.init(MainSetup.java:22) ~[classes/:?]
	at org.nutz.mvc.impl.NutLoading.evalSetup(NutLoading.java:278) ~[nutz-1.r.65.jar:1.r.65]
	at org.nutz.mvc.impl.NutLoading.load(NutLoading.java:121) ~[nutz-1.r.65.jar:1.r.65]
	at org.nutz.mvc.ActionHandler.<init>(ActionHandler.java:19) ~[nutz-1.r.65.jar:1.r.65]
	at org.nutz.mvc.NutFilter._init(NutFilter.java:91) ~[nutz-1.r.65.jar:1.r.65]
	at org.nutz.mvc.NutFilter.init(NutFilter.java:69) ~[nutz-1.r.65.jar:1.r.65]
	at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:285) ~[catalina.jar:8.5.29]
	at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:266) ~[catalina.jar:8.5.29]
	at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:108) ~[catalina.jar:8.5.29]
	at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4598) ~[catalina.jar:8.5.29]
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5241) ~[catalina.jar:8.5.29]
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ~[catalina.jar:8.5.29]
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:754) ~[catalina.jar:8.5.29]
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:730) ~[catalina.jar:8.5.29]
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734) ~[catalina.jar:8.5.29]
	at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1736) ~[catalina.jar:8.5.29]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_161]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_161]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_161]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_161]
	at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300) ~[tomcat-coyote.jar:8.5.29]
	at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) ~[?:1.8.0_161]
	at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) ~[?:1.8.0_161]
	at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:482) ~[catalina.jar:8.5.29]
	at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:431) ~[catalina.jar:8.5.29]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_161]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_161]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_161]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_161]
	at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300) ~[tomcat-coyote.jar:8.5.29]
	at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) ~[?:1.8.0_161]
	at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) ~[?:1.8.0_161]
	at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1468) ~[?:1.8.0_161]
	at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76) ~[?:1.8.0_161]
	at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1309) ~[?:1.8.0_161]
	at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1401) ~[?:1.8.0_161]
	at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:829) ~[?:1.8.0_161]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_161]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_161]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_161]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_161]
	at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:361) ~[?:1.8.0_161]
	at sun.rmi.transport.Transport$1.run(Transport.java:200) ~[?:1.8.0_161]
	at sun.rmi.transport.Transport$1.run(Transport.java:197) ~[?:1.8.0_161]
	at java.security.AccessController.doPrivileged(Native Method) ~[?:1.8.0_161]
	at sun.rmi.transport.Transport.serviceCall(Transport.java:196) ~[?:1.8.0_161]
	at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568) ~[?:1.8.0_161]
	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826) ~[?:1.8.0_161]
	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683) ~[?:1.8.0_161]
	at java.security.AccessController.doPrivileged(Native Method) ~[?:1.8.0_161]
	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682) [?:1.8.0_161]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_161]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_161]
	at java.lang.Thread.run(Thread.java:748) [?:1.8.0_161]
package com.ink.main.model;

import org.nutz.dao.entity.annotation.*;

@Table("t_user")
public class User extends BasePojo{

    @Id//@Id数值主键
    private int id;
    @Name//@Name字符主键
    @Column//@Column字段
    private String name;
    @Column("passwd")
    private String password;
    @Column
    private String salt;
    @One(target=UserProfile.class, field="id", key="userId")
    protected UserProfile profile;

    public int getId() {
        return id;
    }

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

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getSalt() {
        return salt;
    }

    public void setSalt(String salt) {
        this.salt = salt;
    }

    public UserProfile getProfile() {
        return profile;
    }

    public void setProfile(UserProfile profile) {
        this.profile = profile;
    }
}

package com.ink.main.services;

import com.ink.main.model.User;
import org.nutz.dao.Dao;
import org.nutz.dao.util.Daos;
import org.nutz.integration.quartz.NutQuartzCronJobFactory;
import org.nutz.ioc.Ioc;
import org.nutz.mvc.NutConfig;
import org.nutz.mvc.Setup;

import java.util.Date;

public class MainSetup implements Setup {
    // 特别留意一下,是init(初始化)方法,不是destroy(销毁)方法
    public void init(NutConfig nc) {
        Ioc ioc = nc.getIoc();
        Dao dao = ioc.get(Dao.class);
        Daos.createTablesInPackage(dao, "com.ink.main.services", false);

        // 初始化默认根用户
        if (dao.count(User.class) == 0) {
            User user = new User();
            user.setName("admin");
            user.setPassword("123456");
            user.setCreateTime(new Date());
            user.setUpdateTime(new Date());
            dao.insert(user);
        }
        // 获取NutQuartzCronJobFactory从而触发计划任务的初始化与启动
        ioc.get(NutQuartzCronJobFactory.class);
    }

    public void destroy(NutConfig nc) {
        // webapp销毁之前执行的逻辑
        // 这个时候依然可以从nc取出ioc, 然后取出需要的ioc 对象进行操作
    }
}

1 回复

建表扫描的路径错了

Daos.createTablesInPackage(dao, "com.ink.main.model", false);

添加回复
请先登陆
回到顶部