http://mysql.com
選取GA download→MySQL intaller for windows
JDBC下載與安裝
選取connector→connecter/J
解壓縮後jar檔放到C:\tomcat\webapps\你的網站\WEB-INF\lib
MySQL資料庫操作
- 開啟命令列視窗
- cd C:\mysql\bin 切換目錄
- C:\mysql\bin>winmysqladmin 設定使用者名稱和密碼
- C:\mysql\bin>mysql -h localhost -u root -p 進入DBMS
- CREATE DATABASE db-name
- USE db-name
- CREATE TABLE資料表名(name VARCHAR(10), account VARCHAR(20));
- 使用Navicat
database_setup.jsp
----------------------------------
<%@page import="java.sql.*" %>
<%
Connection conn = null;
PreparedStatement pstmt = null;
try{
Class.forName("com.mysql.jdbc.Driver");
String db_name = "database";
String url = "jdbc:mysql://localhost:3306" + db_name +"?useUnicode=true&characterEncoding=utf8";
String user = "root";
String password = "1234";
conn = DriverManager.getConnection(url,user, password);
}catch(SQLException sqle){
out.println("SQL Exception"+sqle);
}
%>
沒有留言:
張貼留言