在MyEclipse中开发jsp的web项目,怎样实现连接数据库SqlServer2000。跪求。
4个回答
展开全部
/*
*连库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;
}
}
*连库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;
}
}
追问
大哥我建了个jsp项目 就是怎样一个方法实现连接SqlServer2000,是不是要加驱动到webinf下的lib文件夹就可以了,三个驱动包
追答
建一个类。就上面那个。加载 mssqlserver.jar 。lib下的包没加载的都加载进取
参考资料: 作者:吕海鹏
2011-02-28
展开全部
除了下面的代码,还要有三个驱动。。。你要网上搜索一下,,java连接sql2000的三个驱动包。。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
追问
我是说web项目,建了个jsp项目,怎样实现连接数据库SqlServer2000
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询