qq_31921921
qq_31921921
采纳率50%
2016-06-24 02:04 阅读 3.3k
已采纳

我连接数据库出现这种问题,求解决啊

java.sql.SQLException: The connection property 'useUnicode' only accepts values of the form: 'true', 'false', 'yes' or 'no'. The value 'ture' is not in this set.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
at com.mysql.jdbc.ConnectionPropertiesImpl$ConnectionProperty.validateStringValues(ConnectionPropertiesImpl.java:309)
at com.mysql.jdbc.ConnectionPropertiesImpl$BooleanConnectionProperty.initializeFrom(ConnectionPropertiesImpl.java:100)
at com.mysql.jdbc.ConnectionPropertiesImpl$ConnectionProperty.initializeFrom(ConnectionPropertiesImpl.java:208)
at com.mysql.jdbc.ConnectionPropertiesImpl.initializeProperties(ConnectionPropertiesImpl.java:2790)
at com.mysql.jdbc.ConnectionImpl.initializeDriverProperties(ConnectionImpl.java:3351)
at com.mysql.jdbc.ConnectionImpl.(ConnectionImpl.java:791)
at com.mysql.jdbc.JDBC4Connection.(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:389)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at util.DB.getConnection(DB.java:31)
at util.DB.main(DB.java:41)

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

5条回答 默认 最新

  • 已采纳
    qq_33859911 乌啼夜的酒痕 2016-06-24 02:07

    老兄,true写反了吧

    点赞 1 评论 复制链接分享
  • qq_31921921 qq_31921921 2016-06-24 02:04

    这是测试代码:package util;

    import java.sql.Connection;
    import java.sql.DriverManager;

    public class DB {
    private static final String driver = "com.mysql.jdbc.Driver";
    private static final String url = "jdbc:mysql://localhost:3306/user?useUnicode=ture&characterEncoding=UTF";
    private static final String username="uroot";
    private static final String password="root";

    private static Connection conn = null;
    
    
    
    
    static{
        try
        {
            Class.forName(driver);
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
    }
    public static Connection getConnection() throws Exception
    {
        if(conn==null)
        {
            conn= DriverManager.getConnection(url, username, password);
            return conn;
        }
        return conn;            
    }
    
    public static void main(String[] a)
    {
        try
        {
        Connection conn = DB.getConnection();
    if(conn!=null)
    {
        System.out.println("数据库连接正常!");
    
    }else{
        System.out.println("数据库连接YI常!");
    
    }
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
    }
    

    }

    点赞 评论 复制链接分享
  • zy_281870667 Bug开发攻城狮 2016-06-24 02:10

    ture ==> true
    如果没用,那就清理下缓存再试试

    点赞 评论 复制链接分享
  • u013478639 Hb_Btd 2016-06-24 02:20

    数据库字段有限制,只能是true,false什么的,现在里面有ture这个值,修改下

    点赞 评论 复制链接分享
  • qq_33456238 qq_33456238 2016-06-24 02:33

    characterEncoding=utf8 少了个8

    点赞 评论 复制链接分享

相关推荐