我用eclipse連接數(shù)據(jù)庫,加載好了驅(qū)動器,為什么連接數(shù)據(jù)庫會出現(xiàn)異常?try { Class.forName("com.mysql.cj.jdbc.Driver"); System.out.println("數(shù)據(jù)庫驅(qū)動加載成功"); java.sql.Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306", "root", "123456"); if(con!=null){ System.out.println("連接數(shù)據(jù)庫成功"); } } catch (ClassNotFoundException e) { // TODO 自動生成的 catch 塊 e.printStackTrace(); } catch (SQLException e) { // TODO 自動生成的 catch 塊 e.printStackTrace(); } }
java連接數(shù)據(jù)庫
淡泊如風(fēng)
2016-09-08 12:04:11