<%@ page import="java.sql.*" language="java" contentType="text/html; charset=utf-8" %> <% Class.forName("com.mysql.jdbc.Driver"); String jdbcUrl = "jdbc:mysql://localhost:3306/ \データベース名?useUnicode=true&characterEncoding=UTF8"; String user = "ユーザ名"; String password = "パスワード"; Connection con = null; Statement st = null; ResultSet rs = null; String sql1 = ""; //データ挿入用 String sql2 = ""; //データ更新用 String sql3 = ""; //データ削除用 String sql = ""; //データ表示用 int cnt; String test = ""; try{ con = DriverManager.getConnection(jdbcUrl,user,password); st = con.createStatement(); //sql = "set client_encoding='UTF8'"; //st.execute(sql); ///// データ挿入 //sql1 = "insert into テーブル名 values('data1','data2','data3')"; //cnt = st.executeUpdate(sql1); ///// データ更新 //sql2 = "update テーブル名 set name='new_data' where name='old_data'"; //cnt = st.executeUpdate(sql2); ///// データ削除 //sql3 = "delete from テーブル名 where name='data'"; //cnt = st.executeUpdate(sql3); sql = "select * from テーブル名"; rs = null; rs = st.executeQuery(sql); while(rs.next()){ test += rs.getString("name") + " / "; test += rs.getString("telno") + " / "; test += rs.getString("email") + "
"; } }catch(Exception e){ System.out.println(e); }finally{ try{ if(rs != null){ rs.close(); } if(st != null){ st.close(); } if(con != null){ con.close(); } }catch(Exception e){ } } %> Java JSP MySQL TEST

DB接続テスト(Java JSP MySQL版)

<%=test%>