jdbc驱动连接mysql的问题
<%@ page language= "java " contentType= "text/html; charset=GB2312 " pageEncoding= "GB2312 "%>
<%@ page import= "java.util.* " %>
<%@ page import= "java.sql.* " %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN ">
<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=GB2312 ">
<title> 创建数据库 </title>
</head>
<body > <font size=2>
<%
//连接需要的对象
Connection conn = null;
Statement stmt = null;
String sql = null;
ResultSet rs = null;
int ret;
try{
/*请确认已经安装mysql服务器,并且用户名root,密码为root*/
Class.forName( "com.mysql.jdbc.Driver "); //载入JDBC驱动程序
String strCon = "jdbc:mysql://localhost:3306/ "; //连接字
conn = DriverManager.getConnection(strCon, "root ", "5201314 "); //连接数据库
stmt = conn.createStatement(); //初始化查询
sql = "create database JspSamples "; //创建数据库
ret = stmt.executeUpdate(sql); //执行创建数据库
sql = "use JspSamples "; //选择数据库
ret = stmt.executeUpdate(sql); //执行选择数据库
sql = " CREATE TABLE customers( " + //创建表
" Id int(6) unsigned NOT NULL auto_increment, " +
" Name varchar(20) default NULL, " +
" addTime timestamp NULL default NULL, " +
" Tel varchar(15) default NULL, " +
" Email varchar(20) default NULL, " +
" PRIMARY KEY (Id) " +
" ) ";
ret = stmt.executeUpdate(sql); //执行创建表
}
catch(
ClassNotFoundException e){ //意外处理,驱动程序无法找到
e.printStackTrace();
out.println( " <h1> 无法找到数据库驱动 </h1> ");
}
catch(
SQLException e1){ //意外处理,数据库操作失败
e1.printStackTrace();
out.println( " <h1> 数据库操作失败 </h1> ");
}
out.println( " <h1> 新建数据库JspSamples成功 </h1> ");
DatabaseMetaData meta = conn.getMetaData(); //获取数据库信息
out.println( " <br> ");
out.println( "连接字: " + meta.getURL()); //获取连接字
out.println( " <br> ");
out.println( "数据库产品: " + meta.getDatabaseProductName()); //获取数据库产品名
out.println( " <br> ");
out.println( "数据库版本: " + meta.getDatabaseProductVersion() ); //获取数据库产品版本
out.println( " <br> ");
out.println( "驱动程序: " + meta.getDriverName() ); //获取数据库驱动名
ou