js| Data | database | Problem due to system requirements, recently in the development process of the system from the original MySQL transferred to SQL 2000, which encountered a lot of problems, it took me a lot of time. Now take my experience to tell everyone, so that everyone less detours, save time.
The first is the installation of the SQL 2000 database, here I mainly talk about the version of SQL 2000 and the compatibility of the operating system: SQL 2000 has a total of 7 different versions, to meet the needs of different levels of users.
I tried, in the XP system only "personal development version" can be installed without errors, so you should be aware of the installation, the specific installation of the configuration reference to the relevant instructions on it.
Here's how to connect to a SQL 2000 database, and, of course, to download the JDBC driver, preferably on the Microsoft website, and then put the three jar packages you downloaded into the web-inf/lib/of your Web application. Next, write the program to test:
/***********************************************/*/*dbtest.java/*/******************************************* * Import java.sql.*; public class Dbtest {Connection con; Statement STA; ResultSet rs; String driver; String URL; String user; String pwd; Public dbtest () {driver = "com.microsoft.jdbc. Sql server. SQLServerDriver ";; url = "Jdbc:microsoft:sqlserver://localhost:1433;databasename =test"; Test is the database name user = "SA"; PWD = "sa"; Please change to your corresponding user and password init (); public void init () {try{class.forname (driver); System.out.println ("Driver is OK"); con = drivermanager.getconnection (url,user,pwd); System.out.println ("conection is OK"); STA = Con.createstatement (); rs = Sta.executequery ("Select * from room"); while (Rs.next ()) System.out.println (Rs.getint ("Roomnum")); }catch (Exception e) {e.printstacktrace (); }} public static void Main (String args[])//self replacement [] {nEW dbtest (); } }
In principle, this code should be correct, but first let's see if the Sqlser server is not upgraded to SP3 (when using JDBC, if the system is XP or 2003 make sure to upgrade SQL Server to SP3, everywhere), let's look at the results of the operation:
Driver is okjava.sql.SQLException: [microsoft][sqlserver driver for jdbc]error socket. At Com.microsoft.jdbc.base.BaseExceptions.createException (Unknown Source) at com.microsoft.jdbc.base.BaseException S.getexception (Unknown source) at Com.microsoft.jdbc.base.BaseExceptions.getException (Unknown source) at COM .microsoft.jdbc.sqlserver.tds.tdsconnection.<init> (Unknown Source) at Com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open (Unknown Source) at Com.microsoft.jdbc.base.BaseConnection.getNewImplConnection (Unknown Source) at Com.microsoft.jdbc.base.BaseConnection.open (Unknown Source) at Com.microsoft.jdbc.base.BaseDriver.connect (Unknown Source) at Java.sql.DriverManager.getConnection (drivermanager.java:523) at Java.sql.DriverManager.getConnect Ion (drivermanager.java:171) at Dbtest.init (dbtest.java:32) at dbtest.<init> (dbtest.java:25) at Dbtest.main (dbtest.java:46Press any key to continue ...
[1] [2] Next page