SQL Server prepares:
1. Right-click Database Open Properties
2. Security--sql identity and Windows authentication
3. In data login sa, select attribute Change Password: for example 123456
4. Open Configuration Manager: Enable TCP/IP and Names pipes protocol
5. Restart the service to the end of the database configuration!
Next:
I. Configuring an ODBC data source
To configure ODBC:
Control Panel-----Management Tools-----Data Sources (ODBC)
System DSN-----Add----SQL Server-----name MSSQL, server: 127.0.0.1----Fill in the User name password test, the most critical is to configure the client:
Server name is 127.0.0.1, choose TCP/IP, the following basic is OK, finally pay attention to test the data source
Step Two: Guide package test (test using Sqljdbc4.rar)
Decompression Sqljdbc4.rar
Find this Sqljdbc4.jar bag, cut to where you want it to go ( recommended jre\lib in the JDK installation directory to match Eclipse is good management , this is only the Eclipse environment configuration, of course, not to carry the environment variable classpth can also be
2. Configure Eclipse
Window------Preferences-----Java------Installed JRE----Add an external jar find the newly moved Sqljdbc.jar file and add it in.
Finally crazy press Finish OK what!
Code Verification:
public static void Main (String...arg) {String driver= "com.microsoft.sqlserver.jdbc.SQLServerDriver"; String url= "Jdbc:sqlserver://localhost:1433;databasename=master"; String user= "sa", password= "123456"; Here is your sa account password try {class.forname (driver);} catch (ClassNotFoundException e) {System.out.println ("Driver load Failed");} Java.sql.Connection con=null;try {con=drivermanager.getconnection (Url,user,password);} catch (SQLException e) { System.out.println ("Connection Failed");} if (con!=null) System.out.println ("Connection succeeded:" +con);}
What is your result?
Of course not very normal, if not well, it doesn't matter, landlord for small white prepare an illustrated with the jar Package Tutorial: in the resources:
Special Tutorial number password is 20144206199
Come on, get it done.
Although Jdbc+mysql relatively fast, but inevitably encountered a tricky SQL Server, MSSQL PDO+SQLSVR is the big hole! Share it next time.
Java Connect SQL Server