急用java 连接sql server 2008 的驱动包,以及java代码的数据库连接之前的驱动安装位置和方法!
3个回答
展开全部
驱动类:com.microsoft.sqlserver.jdbc.SQLServerDriver
链接方法:jdbc:sqlserver://IP:端口;DatabaseName=数据库
public class DB {
Statement stmt;
String mc;
Connection conn = null;
CachedRowSetImpl crs;
public static String url = "jdbc:sqlserver://127.0.0.1:1433;DatabaseName=test";
public static String user = "sa";
public static String password = "123";
public DB() {}
public CachedRowSetImpl dbquery(String sqlstr){//查询时调用该方法
System.out.println("-*-*-*-*-*-*-*-chaxun-*-*-*-*-*-*-*" + sqlstr);
try
{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
conn= DriverManager.getConnection(url,user,password);
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
crs=new CachedRowSetImpl();
ResultSet rs=stmt.executeQuery(sqlstr);
crs.populate(rs);
if(rs!=null)
{
rs.close();
stmt.close();
rs=null;
stmt=null;
}
conn.close();
}catch(Exception e)
{
System.out.println("s4:"+e.toString());
//e.printStackTrace();
}
return crs;
}
public void dbexe(String sqlstr){//用于增加、删除、修改
System.out.println("-*-*-*-*-*-*-*-caozuo-*-*-*-*-*-*-*" + sqlstr);
try
{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
conn= DriverManager.getConnection(url,user,password);
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
stmt.execute(sqlstr);
stmt.close();
conn.close();
}
catch(Exception e)
{
System.out.println(e.toString());
}
}
}
驱动包你给我 留个联系方式我发给你!
有问题可百度Hi我!good luck!~
链接方法:jdbc:sqlserver://IP:端口;DatabaseName=数据库
public class DB {
Statement stmt;
String mc;
Connection conn = null;
CachedRowSetImpl crs;
public static String url = "jdbc:sqlserver://127.0.0.1:1433;DatabaseName=test";
public static String user = "sa";
public static String password = "123";
public DB() {}
public CachedRowSetImpl dbquery(String sqlstr){//查询时调用该方法
System.out.println("-*-*-*-*-*-*-*-chaxun-*-*-*-*-*-*-*" + sqlstr);
try
{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
conn= DriverManager.getConnection(url,user,password);
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
crs=new CachedRowSetImpl();
ResultSet rs=stmt.executeQuery(sqlstr);
crs.populate(rs);
if(rs!=null)
{
rs.close();
stmt.close();
rs=null;
stmt=null;
}
conn.close();
}catch(Exception e)
{
System.out.println("s4:"+e.toString());
//e.printStackTrace();
}
return crs;
}
public void dbexe(String sqlstr){//用于增加、删除、修改
System.out.println("-*-*-*-*-*-*-*-caozuo-*-*-*-*-*-*-*" + sqlstr);
try
{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
conn= DriverManager.getConnection(url,user,password);
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
stmt.execute(sqlstr);
stmt.close();
conn.close();
}
catch(Exception e)
{
System.out.println(e.toString());
}
}
}
驱动包你给我 留个联系方式我发给你!
有问题可百度Hi我!good luck!~
追问
把这个包导入到哪里?不用配置数据源吗?
追答
包放到tomcat的lib下或者web、项目的lib下就可以
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询