当前位置: 代码迷 >> Java Web开发 >> sql 异常啊 大家看错哪了
  详细解决方案

sql 异常啊 大家看错哪了

热度:750   发布时间:2016-04-17 01:14:19.0
sql 错误啊 大家看哪里错了
Java code
package com.fox_ice.servlet;import java.io.*;import javax.servlet.*;import javax.servlet.http.*;import java.sql.*;public class CreateDBServlet2 extends HttpServlet{        String url1;        String user;        String password;        String driverClass;        public void init()  throws ServletException        {                driverClass=getInitParameter("driverClass");                url1=getInitParameter("url");                user=getInitParameter("user");                password=getInitParameter("password");                                try                {                        Class.forName(driverClass);                }                catch(ClassNotFoundException ce)                {                    ce.printStackTrace();                }                        }     public void  doGet(HttpServletRequest request,HttpServletResponse response) throws IOException,ServletException        {            Connection conn=null;            Statement stmt=null;            request.setCharacterEncoding("gbk");            try            {                conn=DriverManager.getConnection(url1,user,password);                stmt=conn.createStatement();             stmt.executeUpdate("drop database if exists guest");                    stmt.executeUpdate("create database guest");                stmt.executeUpdate("use guest");                stmt.executeUpdate("create table guestbook(id INT not null primary key,title VARCHAR(50) not null,author VARCHAR(50) not null,contents VARCHAR(100) not null");            stmt.addBatch("insert into guestbook values(1,'我的留言','fox_ice','我的留言我的留言我的留言我的留言我的留言')");        stmt.addBatch("insert into guestbook values(2,'我的留言','fox_ice','我的留言我的留言我的留言我的留言我的留言')");        stmt.addBatch("insert into guestbook values(3,'我的留言','fox_ice','我的留言我的留言我的留言我的留言我的留言')");        stmt.executeBatch();                response.setContentType("text/html;charset=gb2312");        PrintWriter out=response.getWriter();        out.println("数据库建表成功");        out.close();            }            catch(SQLException se)            {                se.printStackTrace();            }                finally            {                if(null!=conn)                {                    try                    {                        conn.close();                    }                    catch(SQLException se)                    {                        se.printStackTrace();                    }                                        conn=null;                }                if(null!=stmt)                {                    try                    {                        stmt.close();                    }                    catch(SQLException se)                    {                        se.printStackTrace();                    }                   stmt=null;                    }                            }         }                    }


------解决方案--------------------
create table guestbook(id INT not null primary key,title VARCHAR(50) not null,author VARCHAR(50) not null,contents VARCHAR(100) not null

少个)
其他 的SQLSERVER知识忘完了;

不知道建立数据库是不是楼主这么建的。

LX解答吧
  相关解决方案