JAVA连接SQL2000 JDBC问题 com.microsoft.jdbc.sqlserver.SQLServerDriver No suitable driver found for
提示!com.microsoft.jdbc.sqlserver.SQLServerDriverNosuitabledriverfoundforjdbc:microsoft...
提示!
com.microsoft.jdbc.sqlserver.SQLServerDriver
No suitable driver found for jdbc:microsoft:sqlserver://localhost:1433;DatabaseN
ame=libmanager
Press any key to continue...
怎么改能连接上
代码如下
import java.sql.*;
public class ConDB {
Connection conn = null;
CallableStatement statement = null;
Statement stmt = null;
ResultSet rs = null;
// 导入驱动
public ConDB() {
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
} catch (java.lang.ClassNotFoundException e) {
System.err.println(e.getMessage());
}
}
// 数据库查询
public ResultSet executeQuery(String sql) {
try {
conn = DriverManager
.getConnection(
"jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=libmanager",
"sa", "");
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
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 {
conn = DriverManager
.getConnection(
"jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=libmanager",
"sa", "");
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
result = stmt.executeUpdate(sql);
} catch (SQLException ex) {
System.err.println(ex.getMessage());
result = 0;
}
return result;
}
// 调用存储过程
public ResultSet executeProcedure(String sql) {
try {
conn = DriverManager
.getConnection(
"jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=libmanager",
"sa", "");
statement = conn.prepareCall(sql);
statement.execute();
rs = statement.getResultSet();
} catch (SQLException ex) {
System.err.println(ex);
}
return rs;
}
public static void main(String[] args){
ConDB ff=new ConDB();
ResultSet rs = ff.executeQuery("SELECT top 5 * FROM Books order by Totaljie desc");
try{
while(rs.next()){
System.out.println(rs.getString("Bookname".trim()));
}
}
catch(Exception e){}
}
}
把JAR包放进classpath里面???
一楼能不能说?细点?
什么是JAR包??classpath?? 展开
com.microsoft.jdbc.sqlserver.SQLServerDriver
No suitable driver found for jdbc:microsoft:sqlserver://localhost:1433;DatabaseN
ame=libmanager
Press any key to continue...
怎么改能连接上
代码如下
import java.sql.*;
public class ConDB {
Connection conn = null;
CallableStatement statement = null;
Statement stmt = null;
ResultSet rs = null;
// 导入驱动
public ConDB() {
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
} catch (java.lang.ClassNotFoundException e) {
System.err.println(e.getMessage());
}
}
// 数据库查询
public ResultSet executeQuery(String sql) {
try {
conn = DriverManager
.getConnection(
"jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=libmanager",
"sa", "");
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
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 {
conn = DriverManager
.getConnection(
"jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=libmanager",
"sa", "");
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
result = stmt.executeUpdate(sql);
} catch (SQLException ex) {
System.err.println(ex.getMessage());
result = 0;
}
return result;
}
// 调用存储过程
public ResultSet executeProcedure(String sql) {
try {
conn = DriverManager
.getConnection(
"jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=libmanager",
"sa", "");
statement = conn.prepareCall(sql);
statement.execute();
rs = statement.getResultSet();
} catch (SQLException ex) {
System.err.println(ex);
}
return rs;
}
public static void main(String[] args){
ConDB ff=new ConDB();
ResultSet rs = ff.executeQuery("SELECT top 5 * FROM Books order by Totaljie desc");
try{
while(rs.next()){
System.out.println(rs.getString("Bookname".trim()));
}
}
catch(Exception e){}
}
}
把JAR包放进classpath里面???
一楼能不能说?细点?
什么是JAR包??classpath?? 展开
5个回答
展开全部
三个jar包,你有吗,没有我传你百度hi随时在线
msbase.jar
mssqlserver.jar
msutil.jar
msbase.jar
mssqlserver.jar
msutil.jar
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
他们说得都对.提示就是缺少驱动包.你需要下载sql 2000的SP3 和SP4补丁.然后下栽JDBC,把JDBC的包拷到项目的lib目录下.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
需要有sqlserver2000的jar包,然后把JAR包放进classpath里面,有可能是jar包不合适
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
把JAR包放进classpath里面
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询