sqlserver数据库问题

daemonys 2004-09-29 10:58:13
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*,java.io.*"%>

<html>
<body>
<center>
<html>

一些比较少使用的操作<hr>
<table border=1>
<%
try
{

//装载驱动程序
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();

//创建连接
Connection con=java.sql.DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1433","bn","bn");

Statement stmt=con.createStatement();
try
{
stmt.execute("drop database test_database;");//删除数据库
stmt.execute("create database test_database;");//创建数据库
}
catch(SQLException e)
{
out.println(e.getMessage());
}

stmt.execute("use test_database;create table test(t int,t2 varchar(20))");//在数据库里添加表
stmt.execute("use test_database;alter table test add t3 varchar(20) null");//更改表的结构
stmt.execute("use test_database; insert into test values(12,'hellking','asiapower')");
stmt.execute("use test_database; insert into test values(12,'hellking2','asiapower2')");
out.println("执行完成");
//关闭连接、释放资源

stmt.close();
con.close();
}
catch(Exception e)
{
e.printStackTrace();
}
%>

<center>
</body>
</html>

上面这段程序会报错,如下:
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]在
数据库 'master' 中拒绝了 CREATE DATABASE 权限。
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source
)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown
Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown
Source)
at com.microsoft.jdbc.sqlserver.tds.TDSExecuteRequest.processReplyToken(
Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Sour
ce)
at com.microsoft.jdbc.sqlserver.SQLServerImplStatement.getNextResultType
(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.commonTransitionToState(Unknown
Source)
at com.microsoft.jdbc.base.BaseStatement.postImplExecute(Unknown Source)

at com.microsoft.jdbc.base.BaseStatement.commonExecute(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.executeInternal(Unknown Source)

at com.microsoft.jdbc.base.BaseStatement.execute(Unknown Source)
at org.apache.jsp.misc_005foperation_jsp._jspService(misc_005foperation_
jsp.java:65)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper
.java:324)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:2
92)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:157)
at com.jspdev.ch8.EncodingFilter.doFilter(EncodingFilter.java:38)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:186)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(Standard
ContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:118)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)

at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:16
0)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
ssConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java
:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadP
ool.java:683)
at java.lang.Thread.run(Thread.java:536)

那位大侠指点一下
...全文
42 点赞 收藏 4
写回复
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
daemonys 2004-09-30
可是我缺省的数据库不是master阿,它怎么说不能在master里面创建数据库
回复
njeshop 2004-09-30
把Connection con=java.sql.DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1433","bn","bn");


改成这样:Connection con=java.sql.DriverManager.getConnection("jdbc:microsoft:sqlserver://192.168.0.29:1433;DatabaseName=test_database;SelectMethod=cursor","bn","bn");
把stmt.execute("use test_database;create table test(t int,t2 varchar(20))");//在数据库里添加表
这个改为:
stmt.execute("create table test(t int,t2 varchar(20))");//在数据库里添加表



回复
skyboy0720 2004-09-29
还有,不明白,你为什么要在MASTER数据库里操作东西!!
回复
skyboy0720 2004-09-29
数据库 'master' 中拒绝了 CREATE DATABASE 权限
已经很清楚了啊!!

看看你的帐号在MASTER里是否有写的权限!!!
回复
发动态
发帖子
Web 开发
创建于2007-09-28

7.9w+

社区成员

Java Web 开发
申请成为版主
社区公告
暂无公告