您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 项目/工程管理 > sqlserver2005数据库驱动jar包
sqlserver2005数据库驱动jar包1.下载sqlserver2005数据库驱动jar包;2.把sqljdbc.jar放在Tomcat安装目录的lib文件夹下;3.MyEclipse环境---Project---Properties---javaBuildPath---Libraries---AddExternalJARs;packagejdbc;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.ResultSet;importjava.sql.SQLException;importjava.sql.Statement;publicclassConnectionSq{jdbc:sqlserver://localhost:1433;databaseName=MyServer//可以解压sqljdbc.jar看看Driver的path是什么privateStringDriver=com.microsoft.sqlserver.jdbc.SQLServerDriver;privateStringurl=jdbc:sqlserver://localhost:1433;databaseName=chen;privateStringuser=sa;privateStringpwd=123;privateConnectionconn=null;publicConnectiongetConnection(){try{Class.forName(Driver);try{conn=DriverManager.getConnection(url,user,pwd);}catch(SQLExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}}catch(ClassNotFoundExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}returnconn;}publicstaticvoidmain(String[]args){ConnectionSqcs=newConnectionSq();Connectionc=cs.getConnection();if(c!=null){System.out.println(successful);}try{Statementsl=c.createStatement();Stringsql=select*fromuser1;ResultSetrs=sl.executeQuery(sql);while(rs.next()){System.out.println(rs.getString(name));}rs.close();sl.close();c.close();}catch(SQLExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}}}
本文标题:sqlserver2005数据库驱动jar包
链接地址:https://www.777doc.com/doc-2860190 .html