<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*,java.io.*"%>
<html>
<body>
<center>
<html>
数据库的删除与创建
<table width="200" border="0">
  <tr>
    <td><%
   try
   {
    String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";  
    String sConnStr = "jdbc:odbc:try";//“try”的意思就是与刚才设置的数据源名对应; 
    Connection Con = null;
    Statement Stmt = null;
     try          /*加载驱动程序*/
    {
    Class.forName(sDBDriver); 
     }
    catch(java.lang.ClassNotFoundException e)
    { 
   out.print("Connect to Database error: " + e.getMessage());
     }
   try          /*建立连接*/
    {
   Con = DriverManager.getConnection(sConnStr,"sa",""); 
     }
   catch(SQLException e)
   {
   out.print(e.toString());
   }
   Stmt=Con.createStatement();
   try
  {
   Stmt.execute("drop database other;");//删除数据库, 前提该数据库存在
  }
  catch(SQLException e)
  {
  out.println(e.getMessage());
  }
    Stmt.execute("create database other;");//创建数据库
    Stmt.execute("use other;create table one(t int,t2 varchar(16))");//在数据库里添加表
    Stmt.execute("use other;alter table one add t3 varchar(16) null");//更改表的结构
    Stmt.execute("use other; insert into one values(1,'fafa','hehe')");
   out.println("OK");
    //关闭连接、释放资源
    Stmt.close();
    Con.close();
    }
    catch(Exception e)
    {
    e.printStackTrace();
    }    
    %></td>
  </tr>
</table>
<center>
</body>
</html> 
