Home > Database > Mysql Tutorial > How to connect eclipse to sql?

How to connect eclipse to sql?

藏色散人
Release: 2019-05-13 10:29:38
Original
14208 people have browsed it

How to connect eclipse to sql?

Use Eclipse to test the connection to the SQL Server 2008 database:

1. Open SQL Server 2008, create a new database Test in it, and then exit SQL Server 2008.

2. Run Eclipse and create a new Java Project named Test.

3. Right-click the project name, select Build Path → Configure Build Path, select the Libraries tab on the right side of the opened window, then click Add External JARs, find the sqljdbc4jar file and open it, and then click OK Complete the configuration of the build path. As shown in the picture:

How to connect eclipse to sql?

Tips: You can also put the sqljdbc4jar class under jre/lib/ext and put it under tomcat/lib

This way you can Apply to all jsp files to reduce the loading of sqljdbc4jar for each project;

4. Create a new package pkg in Test, create a new class Main in pkg, and enter the following code in it:

package pkg;
import java.sql.*;
public class Main { public static void main(String [] args) {  
String driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver";  
String dbURL="jdbc:sqlserver://localhost:1433;DatabaseName=填写你的数据库名";  
String userName="填写你的用户名,我的是sa";  
String userPwd="填写你的密码"; 
try{Class.forName(driverName);
System.out.println("加载驱动成功!");}
catch(Exception e){e.printStackTrace();
System.out.println("加载驱动失败!");}
try{Connection dbConn=DriverManager.getConnection(dbURL,userName,userPwd);System.out.println("连接数据库成功!");
}catch(Exception e){e.printStackTrace();
System.out.print("SQL Server连接失败!");}}
}
Copy after login

5. Right-click and select run as——>Java Application. If Figure 11 below appears, the connection is successful!

How to connect eclipse to sql?

The above is the detailed content of How to connect eclipse to sql?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template