java中的DriverManager.getConnection数据库连接问题
的有关信息介绍如下:连接不上的话应该是代码写的有问题,可参考下面例子中DriverManager.getConnection的写法:数据库名:select_test用户名:root密码:123456连接成功后显示teacher_table表中的数据。import java.sql.*;class ConnMySql { /** * @param args * @throws Exception */ public static void main(String[] args) throws Exception { // TODO Auto-generated method stub Class.forName("com.mysql.jdbc.Driver"); Connection conn = DriverManager.getConnection( "jdbc:mysql://127.0.0.1:3306lect_test", "root","123456"); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("select * from teacher_table"); while (rs.next()) { System.out.println(rs.getInt(1) + "\t" +rs.getString(2) + "\t" +rs.getString(3) ); } if (rs != null) { rs.close(); } if (stmt != null) { stmt.close(); } if (conn != null) { conn.close(); } } }