public void init() throws ServletException{ try{ Class.forName("org.gjt.mm.mysql.Driver"); String dbURL = "jdbc:mysql://localhost/murach"; String username = "root"; String password = "; connection = DriverManager.getConnection(dbURL, username, password); } catch(ClassNotFoundException e){ System.out.println("找不到数据库驱动程序."); } catch(SQLException e){ System.out.println("不能打开数据库连接: " + e.getMessage()); }} |