jsp连接server2000一般代码及其操作
import java.sql.*;
//连接数据库
public class connpet {
String sDBDriver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=yourdatabase";
String user="yourusername";
String password="yourpassword";
Connection connect = null;
ResultSet rs = null;
public connpet()
{
try
{
Class.forName(sDBDriver);
}
catch(ClassNotFoundException e)
{
System.err.println(e.getMessage());
}
}
public ResultSet executeQuery(String sql)
{
try
{
connect = DriverManager.getConnection(url, user,password);
Statement stmt = connect.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
rs = stmt.executeQuery(sql);
}
catch(SQLException ex)
{
System.err.println(ex.getMessage());
}
return rs;
}
public int executeUpdate(String sql)
{
int result = 0;
try
{
connect = DriverManager.getConnection(url, user,password);
Statement stmt = connect.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
result = stmt.executeUpdate(sql);
}
catch(SQLException e)
{
System.err.println(e.getMessage());
}
return result;
}
}