| |

VerySource

 Forgot password?
 Register
Search
View: 6278|Reply: 40

Java query SQLServer encountered a problem: the object name is invalid.

[Copy link]

2

Threads

12

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-3-23 17:30:02
| Show all posts |Read mode
I used a Statement to query SQLServer, there was no problem connecting to the database, and there was no problem querying the system tables in the database, but when I query the table "userInfo" I created, an exception popped up: "The object name 'userInfo' is invalid". Masters, what is going on? ?
Reply

Use magic Report

2

Threads

16

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-7-2 22:00:01
| Show all posts
If select * from sysobjects succeeds, it means everything is ok
If there is no problem above, please carefully check whether your database has userInfo table
Reply

Use magic Report

2

Threads

16

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-7-3 18:30:01
| Show all posts
Try running it in the query analyzer
Reply

Use magic Report

2

Threads

12

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

 Author| Post time: 2020-7-3 22:15:01
| Show all posts
Query analyzer can be run.

In the program, I use the prepared statement PreparedStatement:
String Query="SELECT id from userInfo where name=? and password=?";
PreparedStatement preStat=conn.prepareStatement(Query);

Will it be related to prepared sentences?
Reply

Use magic Report

2

Threads

12

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

 Author| Post time: 2020-7-4 09:30:01
| Show all posts
I tried it, the following SQL statement can be run in the query analyzer:
SELECT id from userInfo where name='www'and password='000000'

However, when copied to the JAVA program and queried, an error that the object is invalid appears.
Reply

Use magic Report

2

Threads

12

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

 Author| Post time: 2020-7-23 09:00:01
| Show all posts
Still don't know why.
Waiting for someone to resolve it.
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-7-27 14:45:01
| Show all posts
Try to change to direct query
Reply

Use magic Report

2

Threads

16

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-7-28 13:45:01
| Show all posts
Execute in JDBC:
SELECT filename FROM sysfiles1
Print out the filename, the database is definitely not the one you want to connect to
Reply

Use magic Report

2

Threads

12

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 Colombia

 Author| Post time: 2020-7-28 20:00:01
| Show all posts
Now I check the pubs table: SELECT filename FROM sysfiles1
The printed result is:
D:\Program Files\Microsoft SQL Server\MSSQL\data\master.mdf
D:\Program Files\Microsoft SQL Server\MSSQL\data\mastlog.ldf

What's the matter?
Reply

Use magic Report

0

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-7-31 19:30:01
| Show all posts
You choose the default library, not the library where your table is located
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list