Packagessd; importjava. SQL. connection; importjava. SQL. driverManager; importjava. SQL. resultSet; importjava. SQL. statement; publicclasssdd {publicstaticvoidmain (String [] srg) {StringdriverNamecom. microsoft. sqlserver. jdbc. SQLServerDri
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. SQLServerDri
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]ObjectName 'users'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.