alibaba / cobar

a proxy for sharding databases and tables
Apache License 2.0
3.21k stars 1.22k forks source link

cobar-driver使用出问题! #14

Open long1657 opened 10 years ago

long1657 commented 10 years ago

Class.forName("com.alibaba.cobar.jdbc.Driver"); String url = "jdbc:cobar://host:8066/database"; Properties info = new Properties(); info.setProperty("user", "root"); info.setProperty("password", "654321"); Connection connection = null; try { connection = DriverManager.getConnection(url, info); Statement stmt = (Statement) connection.createStatement(); String query = "SELECT COUNT(*) FROM table"; ResultSet rs = stmt.executeQuery(query); while (rs.next()) { System.out.println("总数:" + rs.getString(1)); } rs.close(); stmt.close(); } finally { if (connection != null) { connection.close(); } } 我把cobar-driver包导进去,用上面的代码提示下面的错误: java.sql.SQLException: No suitable driver found for jdbc:cobar://xxxx:8066/database at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at com.demo.cobar.CobarTest.main(CobarTest.java:21) 这种情况如何结局啊?

fishwasser commented 10 years ago

我直接用mysql jdbc driver 都连接不上,显示没有该数据库,这是为什么啊,查不到原因

fishwasser commented 10 years ago

你需要加一句: Class.forName("com.alibaba.cobar.jdbc.Driver");