myEclipse6.5 problems with the database (SQL Server2008) connection did you solve it? < when using the SSH framework, when using servlet+javabean+jsp > personal Experience Summary

Source: Internet
Author: User
Tags microsoft sql server stmt ssh java web tomcat server

Yesterday, because of the construction of the SSH framework, after a year and re-encountered the MyEclipse connection database problems. Needless to say, the dry stuff.

(All of the following are in the order of the problems I encountered, that is, no order, just willful)

Please note: This is a problem in the premise of Myeclipse6.5+sql Server2008, when using MySQL or SQL2000 before, or with Oracle and so on, inside the jar package is different! Do not refer to the following OH ~

1. MyEclipse Database connection creation failed, Driver class not found appears

This is an SSH framework that has an error message when the Sqljdbc4.jar package is loaded when the database is connected. Feel everything follow the steps in the information and make sure the following are correct:

(1) Driver template selection blank

(2) Driver name is sql2008 (the name is casually written),

(3) Connection URL is jdbc:sqlserver://localhost:1433;databasename=master (make sure your database port number is 1433< how to set it, see below; and the computer installed in the sql2008 is known as the master of the database < generally have >)

(4) User name is SA (this is based on your database login time)

(5) password is sql2008 (this is based on your database login time)

(6) Driverclassname is Com.microsoft.sqlserver.jdbc.SQLServerDriver

Add JARs when clearly check the Sqljdbc4.jar package exists, and the information said SQL2005 and above to use Sqljdbc4.jar (do not Sqljdbc.jar pack), but AH but! What if Driver class not found appears on the head? Access to countless information, the original use of the SSH framework is not compared with the use of servlet+javabean+jsp, Only need to Sqljdbc4.jar, this time need two jar package, or this time Sqljdbc.jar more need (sometimes do not need sqljdbc4.jar, look at your system), therefore, download the database Driver Jar package (HTTP/ www.microsoft.com/zh-cn/download/details.aspx?id=21599), unzipped and placed in C:\Program Files (x86) \microsoft SQL Server JDBC Driver

Remember to configure environment variables: computer, properties, advanced system settings, environment variables, double-click the system variable in the CLASSPATH, add the value of the variable; C:\Program Files (x86) \microsoft SQL Server JDBC Driver\sqljdbc_3.0\chs\sqljdbc4.jar (the preceding semicolon; ' Don't forget! )

The front is complete, the jar package also has, basically will not have any big problem, but! This time seems to still not work, it may be the jar package is broken (why it is bad, I did not do ah, but it is someone will meet me this problem, may be copied when the wrong?) In short, any problem can not be checked out, you try to re-download a jar on the official website "here Sqljdbc4.jar and Sqljdbc.jar after decompression--->http://www.microsoft.com/zh-cn/download /details.aspx?id=21599 ")

2, the database TCP/IP protocol is not open, the port number is not set (receive the protocol did not open, you let people database how to communicate with you)

Very simply, start menu->microsoft SQL Server 2008-> Configuration Tool->sql Server Configuration Manager->sql Server network Configuration->sqlexpress protocol, will tcp/ The state of the IP is changed from disabled to Enabled, such as:

Then right-click the TCP/IP point attribute to change the TCP port in IP1 and Ipall to 1433, as (perfect)

3, using the MVC pattern to develop the Java Web Connection database method, I currently know three ways (servlet directly connected The common parameter is initialized in Web. XML, then the parameter connection is called in the servlet, and the connection pool is established, but I'll start with the first one, the most straightforward one today (after all, it's busy today)

When you make sure your database is available, TCP/IP protocol is on, port number is set to 1433, and Sqljdbc4.jar package is ready, start:

(1) Create a servlet under the src file of the project project (this is all right?) Src-new-servlet See settings, then Next-finish)

Then type under the Init method function as follows:

public void Init () throws Servletexception {
try {
Class.forName ("Com.microsoft.sqlserver.jdbc.SQLServerDriver");
String url= "Jdbc:sqlserver://localhost:1433;databasename=mysales";
String user= "SA";
String password= "sql2008";
Conn=drivermanager.getconnection (Url,user,password);

When you enter HTTP://LOCALHOST/MYWEB/SERVLET/JDBCSERVLET1 in the browser, you see I am ssh OK in the MyEclipse console


System.out.println ("I Am myweb OK");
/* Stmt=conn.createstatement (); This is the data code in the output database, no, it doesn't matter.
Stmt.executeupdate ("Use Mysales");
String sql= "SELECT * from Orders";
Rs=stmt.executequery (SQL);
while (Rs.next ()) {
System.out.println (Rs.getint ("OrderID"));
}

*/
System.out.println ();//true
} catch (ClassNotFoundException e) {
E.printstacktrace ();
System.out.println ("MyWeb classnotfoundexception"); Console output That means something went wrong here.
} catch (SQLException e) {
E.printstacktrace ();
System.out.println ("MyWeb SQLException");
}
}

Note the errors that occur when you remove some reference methods, note the addition of

It's simple, right? But there's been a lot of mistakes in your console, right? Check it slowly and correct it, boys.

The last one to share a whole bunch of my mistakes: I can't find the jar package (I don't remember what the error code was at the time, but probably the translator couldn't find the driver, or the driver didn't support anything)

This is the time to use the Sqljdbc4.jar package (because my JDK version is 1.7.0, when the JDK version looks like?). Sqljdbc.jar package is not available when higher than 1.6.0) < How to see the JDK version you installed see below >

Copy the prepared jar package into the Lib folder under the Web INF! (Modify the Java file Remember to restart the Tomcat server to take effect OH)

4. How to check the JDK version?

Start-and-run, and then enter CMD into the DOS interface, enter java-version, the following information can be seen in the JDK version you installed

First come here to stop, feel a lot of problems can be, after slowly say

myEclipse6.5 problems with the database (SQL Server2008) connection did you solve it? < when using the SSH framework, when using servlet+javabean+jsp > personal Experience Summary

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.