<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%@ page import="java.util.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>创建数据库</title>
</head><body>
<%
Connection conn=null;
Statement stmt=null;
String sql=null;
ResultSet rs=null;
int ret;
try{
Class.forName("com.mysql.jdbc.Driver");
String strCon="jdbc:mysql://localhost:3306/";
conn=DriverManager.getConnection(strCon,"root","");stmt=conn.createStatement();
sql="create database aspSample";
ret=stmt.executeUpdate(sql);
sql="use aspSample";
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,"+")";
ret=stmt.executeUpdate(sql);
}catch(ClassNotFoundException e){
e.printStackTrace();
out.println("<H1>地法找到数据库驱动<H1>");
}catch(SQLException el){
el.printStackTrace();
out.println("<H1>数据库操作失败<H1>");
}
out.println("<h1>新建数据库JspSamples成功<h1>");stmt.close();
conn.close();
%></body>
</html>
这个程序为什么运行结果是:数据库操作失败。为什么不能建表;谢谢

解决方案 »

  1.   

    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,"+")"; 

    最后一个小括号前面多了一个逗号
      

  2.   

    正是,你的见表语句最后一行不应该在有一个逗号出现啊 
      问题应该就出在这里啊   Tel varchar(15) default NULL,"+")"; 
      

  3.   

    哦。。   谢谢了。  那在我运行后当我打开JspMyAdmin后,然后在打开customers时出现这样一段文字:Oops! an exception occurred.  
       The exception was: java.sql.SQLException: Access denied for user '123'@'localhost' (using password: YES) 
       The exception class was : class java.sql.SQLException 
      这得怎么解决啊??  谢。