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