In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
How to connect eclipse to sql? Many novices are not very clear about this. In order to help you solve this problem, the following editor will explain it in detail. People with this need can come and learn. I hope you can gain something.
Use Eclipse to test the connection to the SQL Server 2008 database:
1. Open SQL Server 2008, create a new database Test, 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 open window, then click Add External JARs, find the sqljdbc4jar file and open it, and then click OK to complete the configuration of the build path. As shown in the figure:
Tip: you can also put the sqljdbc4jar class under jre/lib/ext and tomcat/lib
This can be applied to all jsp files, reducing the sqljdbc4jar load on each project
4. Create a new package pkg in Test and a new class Main in pkg, and enter the following code:
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= fill in your database name"; String userName= "fill in your user name, mine is sa"; String userPwd= "fill in your password"; try {Class.forName (driverName); System.out.println ("driver loaded successfully!") ;} catch (Exception e) {e.printStackTrace (); System.out.println ("failed to load driver!") ;} try {Connection dbConn=DriverManager.getConnection (dbURL,userName,userPwd); System.out.println ("connect to the database successfully!") ;} catch (Exception e) {e.printStackTrace (); System.out.print ("SQL Server connection failed!") ;}
5. Right-click and select run as-- > Java Application. If you see figure 11 below, the connection is successful!
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.