jbuilder 中提示游标未声明。。。。
沉珂 2006-05-17 01:17:36 package server;
import java.sql.*;
import java.util.Vector;
import javax.swing.JOptionPane;
class AccessDb{
private static AccessDb db=null;
private Connection connection;
Statement stmt=null;
private PreparedStatement sqlFindPassword;//根据用户名查找密码
private String sqlFindAllFieldName="SELECT fileName FROM file";//得到所有文件的文件名
private AccessDb() throws Exception{
connect();
sqlFindPassword=connection.prepareStatement("SELECT password "+"FROM users "
+"WHERE ID = ? ");
}
private void connect() throws Exception
{
String url="jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=mydb;SelectMethod=Cursor;";
String user = "jsjboss";
String password="2202008";
System.out.println("正在加载数据库驱动程序,请稍侯。。。");
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
System.out.println("成功加载SQLServerDriver,正在连接到数据库。。。");
}
catch (ClassNotFoundException e) {
throw new ProgramException("加载SQLServerDriver出错", "数据库驱动没有找到");
}
try{
//connection = DriverManager.getConnection(url, user, password);
connection = DriverManager.getConnection(
"jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs;SelectMethod=Cursor;User=jsjboss;Password=2202008");
connection.setAutoCommit(false);
System.out.println("成功连接到SQL server 2000");
}
catch (SQLException e) {
e.printStackTrace();
System.out.println("连接mydb数据库失败!");
System.exit(1);
}
}
public static AccessDb getInstance (){
if (db == null) {
try{
db = new AccessDb();
}
catch (Exception e){
System.out.println("error:db = new AccessDb()");
e.printStackTrace();
}
}
return db;
}
public void close() throws Exception{
try {
connection.close();
System.out.println("关闭数据库资源成功!");
}
catch (SQLException e) {
throw new ProgramException("关闭数据库资源时出错", "");
}
}
protected void finalize(){//垃圾回收器,关闭数据库连接
try {
close();
}
catch (Exception e) {
e.printStackTrace();
}
}
////////////////////////////////////////////////////////////
///以下是一些操作的类型,在对数据库进行操作时,都是调用下列的方法 //
////////////////////////////////////////////////////////////
public String findPassword(String username){
//根据用户名查找密码
String pwd=null;
try{
sqlFindPassword.setString(1,username);
ResultSet pwdset=sqlFindPassword.executeQuery();
if(!pwdset.next())
{
return null;
}
pwd=pwdset.getString("password");
return pwd;
}catch(SQLException ex){
while (ex!=null){
System.out.println("sqlstate:"+ex.getSQLState());
System.out.println("Message:"+ex.getMessage());
System.out.println("Vendor:"+ex.getErrorCode());
ex=ex.getNextException();
System.out.println("");
}
pwd=null;
}
return pwd;
}
public Vector findAllFileName(){
Vector filenames=new Vector();
String filename="";
try{
stmt=connection.createStatement();
ResultSet rs=stmt.executeQuery(sqlFindAllFieldName);
while(rs.next())
{
filename=rs.getString("fileName");
filenames.add(filename);
}
return filenames;
}catch(SQLException ex){
while (ex!=null){
System.out.println("sqlstate:"+ex.getSQLState());
System.out.println("Message:"+ex.getMessage());
System.out.println("Vendor:"+ex.getErrorCode());
ex=ex.getNextException();
System.out.println("");
}
filenames=null;
}
return filenames;
}
}
执行findPassword()没问题,但执行findAllFileName就提示游标未声明。。。
why???
正在加载数据库驱动程序,请稍侯。。。
成功加载SQLServerDriver,正在连接到数据库。。。
成功连接到SQL server 2000
sqlstate:HY000
Message:[Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]在关键字 'file' 附近有语法错误。
Vendor:156
sqlstate:HY000
Message:[Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]游标未声明。
Vendor:16945
这个是提示。。。。
[Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]对象名 'myfiles' 无效。
为什么我把file表改下名就提示对象名无效???
改回来就可以。。。