當前位置:編程學習大全網 - 網站源碼 - jsp連接mysql數據庫如何實現登錄?

jsp連接mysql數據庫如何實現登錄?

首先得把妳的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就是妳登錄時的用戶名與密碼,其它的壹樣就可以了

  • 上一篇:那位高手知道《高勝算交易策略》裏的DTOSC指標公式怎麽寫嗎?如能不吝賜教,不勝感激!
  • 下一篇:如何在自己的網頁上添加調查問卷?
  • copyright 2024編程學習大全網