如何将Java应用程序与Sql server数据库连接 [英] How do I Connect Java Application with Sql server database
问题描述
Hi
i我正在尝试使用Sql server database 2008(JDBC)连接Java应用程序
1)我在sql server中创建了数据库
Hi
i am trying Connect Java Application with Sql server database 2008(JDBC)
1) I created data base in sql server
create table Emp
(
Emp_id int not null primary key,
Emp_Name nvarchar(50),
Emp_Address nvarchar(50)
)
insert into Emp values(001,'xyz','BBSR')
insert into Emp values(002,'abc','CTC')
2)选择一个类并在eclipse IDE中添加以下代码
2)Taking one class and add the following code in eclipse IDE
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class Demo {
public static void main(String[] args) {
try{
Class.forName("com.microsoft.sqlserver.jdbc.SqlServerDriver");
Connection con=DriverManager.getConnection("jdbc:sqlserver://Servername;database=Employee;"+"IntegratedSecurity=true;");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("Select * from Emp");
while(rs.next())
System.out.println(rs.getInt(1)+ " "+rs.getString(2)+" "+rs.getString(3));
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
但是当我在Eclipse中运行这个程序后发现错误java.lang.ClassNotFoundException:com.microsoft.sqlserver.jdbc.SqlServerDriver。所以如何解决这个问题,请帮助
注意:我在Eclipse IDE的库选项卡下的构建路径中添加了Jarsqljdbc4-2.0.Jar并使用了SQl Server 2008管理工作室Express用于创建数据库。
but when i run this program in Eclipse following error was found "java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SqlServerDriver. So how to solve this, Please help
Note: i added Jar "sqljdbc4-2.0.Jar" in build path under library tab in Eclipse IDE. and using SQl Server 2008 management studio Express for creating a database.
推荐答案
你很幸运,我得到了这个链接,用截图清楚地解释了问题
< a href =http://christopher-erwanda.blogspot.in/2013/03/connecting-jsp-with-sql-server-2008-r2.html>将JSP与SQL Server 2008 R2 Express(JDBC)连接 [ ^ ]
You're lucky, I got this link which explains the issues clearly with screenshots
Connecting JSP with SQL Server 2008 R2 Express (JDBC)[^]
上面的链接已经死了,新的链接是 [IT]将JSP与SQL连接Server 2008 R2 Express(JDBC)。
The link above was dead, the new one is [IT] Connecting JSP with SQL Server 2008 R2 Express (JDBC).
这篇关于如何将Java应用程序与Sql server数据库连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!