oracle jdbc ?useUnicode=true&characterEncoding=utf8加上就报错

driver =oracle.jdbc.OracleDriver
url =jdbc:oracle:thin:@localhost:1521:orcl?useUnicode=true&characterEncoding=utf8

username =jsd1303
password =jsd1303

为什么加上?useUnicode=true&characterEncoding=utf8就会报错啊,不加上我就能获取到,还有就是,原先没用这个命令时MYEclipse 打印con时,是那种乱七八糟的东西,好像是unicode吧,
今天加上这个虽然报错,可是我再删除?useUnicode=true&characterEncoding=utf8后
再 打印 con 竟然是正常的那种字符
jdbc:oracle:thin:@localhost:1521:orcl, UserName=JSD1302, Oracle JDBC driver
好奇怪,为什么啊
=========================
下面是报错的信息(加上?useUnicode=true&characterEncoding=utf8
),不加不报错

Exception in thread "main" org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Listener refused the connection with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
The Connection descriptor used by the client was:
localhost:1521:orcl?useUnicode=true&characterEncoding=utf8
)

?useUnicode=true&characterEncoding=utf8 是解决乱码问题,将oracle的编码改为utf8,如果正确执行的话,编码方式已经改变了,你再次打印就是正常的字符,至于你说的报错,不知道报的是什么错,无法确定。
我看了一下楼主报的错,应该就是你的sid写错了,就是orcl,数据库监听监听你的sid最后无法连接你的数据库,所以楼主你先看一下你懂得orcl这个sid写错了没,如果没错,你在:以及orcl中间加一个空格试一试
温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2018-03-04
jdbc里面Oracle的url不需要加useUnicode=true&characterEncoding=utf8,mySql才需要加这一段来设置编码方式,Oracle在安装数据库的时候就已经设置了,所以不需要再指定了。本回答被网友采纳
相似回答