运行时报错提示“com.microsoft.sqlserver.jdbc.SQLServerException: 没有为参数号 1 设置值。”该怎么解决?
public boolean getbook(String fileName) {
boolean b=false;
//开始链接数据库
conn=BaseDao.getConn();
//准备sql语句
String sql="SELECT ?,?,?,? from BOOK ";
String kind,author,bname;
int price = 0;
PrintWriter pw=null;
FileWriter fw=null;
//编译sql语句
try {
ps=conn.prepareStatement(sql);
//执行SQL,获取结果集rs
ResultSet rs=ps.executeQuery();
//处理结果集
while(rs.next()) {
kind=rs.getString("kind");
author=rs.getString("author");
bname=rs.getString("bname");
price=rs.getInt(price);
String p=Integer.toString(price);
//关联文件
File file=new File(fileName);
if(!file.exists()) {
//判断文件不存在就new新文件写数据
try {
file.createNewFile();
//java IO流和文件关联
pw=new PrintWriter(file);
pw.print(kind+"\t");
pw.print(author+"\t");
pw.print(bname+"\t");
pw.print(p+"\t");
pw.println();
pw.flush();
b=true;
}catch(IOException e) {
e.printStackTrace();
}
}else {
//判断文件存在,写入数据
try {
fw=new FileWriter(fileName,true);
fw.write(kind+"\t");
fw.write(author+"\t");
fw.write(bname+"\t");
fw.write(p+"\t\n");
fw.flush();
b=true;
}catch(IOException e) {
e.printStackTrace();
}
}
}
}catch(SQLException e) {
e.printStackTrace();
System.out.println("数据库连接错误!");
System.exit(1);
}finally {
if(conn!=null) {
try {
//关闭数据库
conn.close();
}catch(SQLException e) {
e.printStackTrace();
}
}
if(pw!=null) {
//关闭IO流
pw.close();
}
if(fw!=null) {
try {
fw.close();
}catch(IOException e) {
e.printStackTrace();
}
}
}
return b;
}