日期:2014-05-20  浏览次数:20733 次

对象名 'pet' 无效。
use master
go
if exists (select * from sysdatabases where name='epet')
drop database epet
create database epet
on 
(
  name ='epet_data',
  filename='d:\java\epet_data.mdf',
  size =5mb,
  filegrowth=15%
)
go 

if exists (select * from sysobjects where name='pet')
drop table pet
------------------------宠物表pet-------------------------
create table pet
(
  id int primary key,
  name varchar(20) not null,
  typename varchar(20) not null,
  price int not null,
  health int not null,
  love int ,
  birthday datetime not null,
  owner_id int ,
  store_id int 
)
-------------------------宠物主人表 PETOWNER-----------------
if exists (select * from sysobjects where name='petowner')
drop table petowner
create table petowner
(
  id int primary key,
  name varchar(20) not null,
  password varchar(20) not null,
  money int default 100  
)
------------------------宠物商店表PETSTORE----------------
if exists (select * from sysobjects where name='petstore')
drop table petstore
create table petstore
(
  id int not null,
  name varchar(20) primary key,
  password varchar(20)not null,
  balance int default 0
)
-------------------------账目表ACCOUNT-----------------------------
if exists (select * from sysobjects where name='acount')
drop table acount
create table acount 
(
  id int primary key,
  deal_type int not null, -------交易类型 2-->用户卖给商店,1-->用户从商店购买
  pet_id int not null,
  owner_id int not null,
  store_id int not null,
  price int not null,
  deal_date datetime not null
)

INSERT INTO PET VALUES(1,'楠楠','雪纳瑞',9,0,99,SYSDATETIME(),NULL,NULL);
INSERT INTO PET VALUES(2,'西西','雪纳瑞',7,0,76,SYSDATETIME(),4,NULL);
INSERT INTO PET VALUES(3,'迪迪','八哥犬',8,0,99,'2011-11-1',NULL,6);
INSERT INTO PET VALUES(4,'雪弗莱','藏獒',14,0,23,'2011-11-5',NULL,33);
go
select * from pet

建了一个这样的数据库,在数据库中可以运行查询pet表,但是用jdbc连接到数据库查询就报错:对象名 'pet' 无效。我是不是还丢了什么东西没写?总感觉数据似乎没提交。因为在oracle中commit后就可以很好的解决类似问题。

------解决方案--------------------
贴java代码
------解决方案--------------------
在数据库中可以对pet表进行查询,说明数据库中表是存在的。
这个就看你数据库写对了没?是不是master数据库呢?
------解决方案--------------------
select * from master.pet试试
------解决方案--------------------
首先你这代码有问题,你当前的用户是
final String USER="sa";
final String PWD="123";
而你要查的表在 master里面。不在当前用户中,所以查不到。
------解决方案--------------------
系统用户是可以查的,但是要加路径,不然怎么知道,你建的表在那里,如果把全用户的表拿出来匹配不太现实,而且不同用户的表名可以相同。权限够高的话 要查是可以,不知道sqlserver怎么表示路径。这种资料应该会介绍啊,楼主自己去翻吧。