<?php
<%@ page import = "java.sql.*"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<html>
<head>
<title>create database</title>
</head>
<body>
<%
try {
Class.forName("com.mysql.jdbc.Driver");
try {
String url="jdbc:mysql://localhost/";
String sql="CREATE DATABASE store";
Connection con=DriverManager.getConnection(url,"root","123");//資料庫連線帳密
if(con.isClosed())
out.println("連線建立失敗");
else
{
sql="CREATE DATABASE store";//新增一個store資料庫
con.createStatement().execute(sql);
sql="use store";
con.createStatement().execute(sql);
out.println("store建立成功");
}
con.close();
}
catch (SQLException sExec) {
out.println("SQL錯誤");
}
}
catch (ClassNotFoundException err) {
out.println("class錯誤");
}
%>
</body>
</html>
?>

cabuchi 發表在 痞客邦 PIXNET 留言(0) 人氣()