java.sql.SQLException: Access denied for user ''@'localhost' (using password: YES)
java.sql.SQLException: Access denied for user ''@'localhost' (using password: YES)
@Test public void test01(){ Properties props = new Properties(); InputStream in = JDBCutil.class.getResourceAsStream("/c3p0.properties"); try { props.load(in); in.close(); ComboPooledDataSource cpds = new ComboPooledDataSource(); cpds.setDriverClass(props.getProperty("cp30.driverClass")); cpds.setJdbcUrl(props.getProperty("c3p0.jdbcUrl")); cpds.setUser(props.getProperty("cp30.user")); cpds.setPassword(props.getProperty("c3p0.password")); cpds.getConnection(); System.out.println("获取连接成功!"); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
首先要导入C3P0的jar
生成datasource语法是标准写法,从properties中获取,出现此错误的原因就是没有获取到获取数据库连接的四大参数,可以先把从properties中的值打印出来看看,对比下。

浙公网安备 33010602011771号