Package SSD; import Java. SQL. connection; import Java. SQL. drivermanager; import Java. SQL. resultset; import Java. SQL. statement; public class SDD {public static void main (string [] SRG) {string drivername = "com. microsoft. sqlserver. JDBC. sqlserverdriver "; // load the JDBC driver string dburl =" JDBC: Microsoft: sqlserver: // 127.0.0.1: 1433; databasename = lianxi "; // connect the server and database string username = "sa"; // password string Password = "sa" ; Connection dbconn = NULL; statement sta = NULL; resultset rs = NULL; try {class. forname (drivername); dbconn = drivermanager. getconnection (dburl, username, password); system. out. println ("database connection successful! "); STA = dbconn. createstatement (); RS = sta.exe cutequery ("select * from users"); While (RS. next () {system. out. println (RS. getstring (1); system. out. println (RS. getstring (2) ;}} catch (exception e) {system. err. println ("exception:" + E. getmessage ());}}}
Appears
Java. SQL. SQLException: [Microsoft] [SQLServer 2000 Driver for JDBC] [SQLServer] The Object Name 'users' is invalid.
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 Source)
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.exe cuteQueryInternal (Unknown Source)
At com.microsoft.jdbc.base.BaseStatement.exe cuteQuery (Unknown Source)
......
Code:
String dbURL = "jdbc: microsoft: sqlserver: // localhost: 1433; DatabaseName = XXX
Note that localhost: 1433; there is a space behind it, so that the Database cannot be found, and the data table in it will certainly not be found.