/*
*连库Bean
*最后修改日期:2007-9-5
*/
package com.deepteach.dao;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DBjdbcConnection
{
//数据库名:deepteach_com 用户名:deepteach_com 密码:lvhaipeng
String sDBDriver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
//数据库
String sConnStr = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=deepteach_com";
//数据库用户名
String user = "deepteach_com";
//数据库用户密码
String password = "lvhaipeng";
Connection connect = null;
ResultSet rs = null;
int count = 0;
public DBjdbcConnection()
{
try
{
Class.forName(sDBDriver);
}
catch(java.lang.ClassNotFoundException e)
{
System.err.println( e.getMessage());
}
}
public ResultSet executeQuery(String sql)
{
rs = null;
try
{
connect = DriverManager.getConnection(sConnStr,user,password);
Statement stmt = connect.createStatement();
rs = stmt.executeQuery(sql);
}
catch(SQLException ex)
{
System.err.println(ex.getMessage());
}
return rs;
}
public int executeUpdate(String sql)
{
try
{
connect = DriverManager.getConnection(sConnStr,user,password);
Statement stmt = connect.createStatement();
count = stmt.executeUpdate(sql);
}
catch(SQLException ex)
{
System.err.println(ex.getMessage());
}
return count;
}
}
除了下面的代码,还要有三个驱动。。。你要网上搜索一下,,java连接sql2000的三个驱动包。。。
sql的驱动包要放在那里?
http://wenku.baidu.com/view/541cc525ccbff121dd3683be.html