(1) The most annoying thing about learning a database is that you don't know how to connect, don't want VS, we call the database directly using a function in WPF, but in Java we use JDBC technology,
So our approach must be a bit more complicated! Read a lot of blog clear, tried a lot of methods or unsuccessful, finally saw the "Javaweb technical details" suddenly dawned, special to everyone to share!
(2) First look at my Project organization:
The one with the mark is need to prepare, the Lib directory for the jar package on the Web download, manageusers for their own written test program!
(3) If you are ready for the four jar packages in the Lib directory, start the configuration:
Click Project Right--properies---Java Bulid Path-----Libraries---Add JARs---Popup box click on your project-find Lib directory select four jar package OK----in ok!
(4) then configure your SQL Server;
Find SQL Server ConfigurationManager find 1 cleavage See TCP/IP as "disabled" and turn it on as shown below!
(5) Demo Code manageusers (the XML configuration of the servlet is configured)
Package Com.lc.view;import Java.io.ioexception;import Java.io.printwriter;import java.sql.connection;import Java.sql.drivermanager;import Java.sql.preparedstatement;import Java.sql.resultset;import Javax.servlet.servletexception;import Javax.servlet.http.httpservlet;import Javax.servlet.http.httpservletrequest;import Javax.servlet.http.httpservletresponse;public class ManageUsers Extends Httpservlet{public void doget (HttpServletRequest request, httpservletresponse response) throws Servletexception, Ioexception{response.setcontenttype ("Text/html;charset=utf-8"); PrintWriter out = Response.getwriter (); Out.println ("(6) Run as follows:
(7) It has been successful! If you have problems in this area, you are welcome to ask questions and learn together!
In addition, if you encounter a problem connecting to the database Welcome to my collation of some of the error handling methods: http://blog.csdn.net/xlgen157387/article/details/39055085
Finally, I wish you success!
Myeclipse10.7 connecting SQL Server database technology