MyEclipse ways to add a SQL Server 2008 database

Source: Internet
Author: User

MyEclipse ways to add a SQL Server 2008 database

In general, when configuring the environment, if you want to use the database, you need to connect the programming tools with the database. Now, the small series for you to introduce, myeclipse add SQL Server 2008 Database method, we hope to help

1, in the environment variable, add Sqljdbc.jar path under CLASSPATH (can directly copy Sqljdbc.jar to JDK directory)

2, set up the SQLExpress server, start the TCP/IP service (skip this step if it is turned on), restart the server

3. In MyEclipse, Window---Preferences----and Java-to-installed JREs, click Edit to add the existing jar and select the previous Sqljdbc.jar.

4, the configuration is complete, when creating a new Web project will automatically add this database connection

5. Select a project right-click Test in the Catalog window, select Build Path---Configure build path ..., add extension jar file, add Sqljdbc.jar to it

6. Write Java code to test the connection database

Import java.sql.*;

public class Test {

public static void Main (string[] SRG) {

String drivername = "Com.microsoft.sqlserver.jdbc.SQLServerDriver"; Loading the JDBC Driver

String Dburl = "jdbc:sqlserver://localhost:1433; Databasename=information ";

String userName = "sa";

String userpwd = "123";

Connection Dbconn;

try {

Class.forName (drivername);

Dbconn = Drivermanager.getconnection (Dburl, UserName, userpwd);

System.out.println ("Connection successful!");

} catch (Exception e) {

E.printstacktrace ();

}

}

}

MyEclipse ways to add a SQL Server 2008 database

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.