jsp页面中String sql = "select * from users"; ResultSet rs = connection.executeQuery(sql);报错
packagep7;importjava.sql.*;publicclassJDBConnection{privatefinalStringdbDriver="com.m...
package p7;
import java.sql.*;
public class JDBConnection {
private final String dbDriver="com.microsoft.jdbc.sqlserver.SQLServerDriver";
private final String url="jdbc:microsoft:sqlserver://localhost:1433;DataBaseName=sy_users";
private final String userName="sa";
private final String password="";
private Connection con=null;
public JDBConnection(){
try {
Class.forName(dbDriver).newInstance();
}catch(Exception ex){
System.out.println("数据库加载失败");
}
}
public boolean creatConnection(){
try{
con=DriverManager.getConnection(url,userName,password);
con.setAutoCommit(true);
}catch(SQLException e){
}
return true;
}
public boolean executeUpdate(String sql){
if(con==null){
creatConnection();
}
try{
Statement stmt=con.createStatement();
int iCount=stmt.executeUpdate(sql);
System.out.println("操作成功,所影响的记录数为"+String.valueOf(iCount));
return true;
}catch(SQLException e){
return false;
}
}
public ResultSet executeQuery(String sql){
ResultSet rs;
try{
if(con==null){
creatConnection();
}
Statement stmt=con.createStatement();
rs=stmt.executeQuery(sql);
return rs;
}catch(Exception e){
return null;
}
}
public void closeConnection(){
if(con==null){
try{
con.close();
}catch(SQLException e){
}
}
}
}
JDBConnection connection = new JDBConnection();
String sql = "select * from users";
ResultSet rs = connection.executeQuery(sql);
说ResultSet cannot be resolved to a type 展开
import java.sql.*;
public class JDBConnection {
private final String dbDriver="com.microsoft.jdbc.sqlserver.SQLServerDriver";
private final String url="jdbc:microsoft:sqlserver://localhost:1433;DataBaseName=sy_users";
private final String userName="sa";
private final String password="";
private Connection con=null;
public JDBConnection(){
try {
Class.forName(dbDriver).newInstance();
}catch(Exception ex){
System.out.println("数据库加载失败");
}
}
public boolean creatConnection(){
try{
con=DriverManager.getConnection(url,userName,password);
con.setAutoCommit(true);
}catch(SQLException e){
}
return true;
}
public boolean executeUpdate(String sql){
if(con==null){
creatConnection();
}
try{
Statement stmt=con.createStatement();
int iCount=stmt.executeUpdate(sql);
System.out.println("操作成功,所影响的记录数为"+String.valueOf(iCount));
return true;
}catch(SQLException e){
return false;
}
}
public ResultSet executeQuery(String sql){
ResultSet rs;
try{
if(con==null){
creatConnection();
}
Statement stmt=con.createStatement();
rs=stmt.executeQuery(sql);
return rs;
}catch(Exception e){
return null;
}
}
public void closeConnection(){
if(con==null){
try{
con.close();
}catch(SQLException e){
}
}
}
}
JDBConnection connection = new JDBConnection();
String sql = "select * from users";
ResultSet rs = connection.executeQuery(sql);
说ResultSet cannot be resolved to a type 展开
2011-04-13
展开全部
dbDriver= "com.microsoft.sqlserver.jdbc.SQLServerDriver";
url="jdbc:sqlserver://localhost:1433;DataBaseName=sy_users";
rs应该为空。
url="jdbc:sqlserver://localhost:1433;DataBaseName=sy_users";
rs应该为空。
追问
也试过了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你把ResultSet定义放到private Connection con=null;下面
也定义为null
也定义为null
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询