首先得把妳的mysql的連接jar包導入到Web?App? Libraries
如下圖顯示,mysql-connector-java-5.1.24-bin-jar位於Web?App? Libraries下
假如沒有這個jar包,從網上下載
接著給妳連接的代碼
<%
Class.forName("com.mysql.jdbc.Driver");
String?url?=?"jdbc:mysql://localhost/bbs?user=root&password=root";
Connection?conn?=?DriverManager.getConnection(url);
Statement?stmt?=?conn.createStatement();
ResultSet?rs?=?stmt.executeQuery("select?*?from?article?where?pid?=?"?+?0);
if?(rs.next())?{
if(rs.getInt("isleaf")!=0)?{
tree(conn,rs.getInt("pid"),1);
}
}
%>
這樣就連接上了
String?url?=?"jdbc:mysql://localhost/bbs?user=root&password=root";中,bbs是我自己定義的數據庫,user=root&password=root就是妳登錄時的用戶名與密碼,其它的壹樣就可以了