com.microsoft.sqlserver.jdbc.SQLServerException: 列名 'isbn' 无效。 at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:197)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1493)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:390)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:340)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4575)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1400)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:179)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:154)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeQuery(SQLServerPreparedStatement.java:283)
at y2javaee.sg.ch03.TitlesBean.getTitles(TitlesBean.java:19)
at org.apache.jsp.ch05.books_jsp._jspService(books_jsp.java:103)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)代码如下:
titlesQuery = connection.prepareStatement("select isbn,title,editionNumber," + "copyright,publisherID,imageFile,price" + "from titles order by title");
book.setISBN(results.getString("isbn"));
book.setTitle(results.getString("title"));
book.setEditionNumber(results.getInt("editionNumber"));
book.setCopyright(results.getString("copyright"));
book.setPublisherID(results.getInt("publisherID"));
book.setImageFile(results.getString("imageFile"));
book.setPrice(results.getDouble("price"));
对应数据库里的表create table titles(
isbn varchar(20) primary key,
title varchar(100),
editionNumber int,
copyright varchar(20),
publisherID int,
imageFile varchar(20),
price numeric(9)
)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1493)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:390)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:340)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4575)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1400)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:179)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:154)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeQuery(SQLServerPreparedStatement.java:283)
at y2javaee.sg.ch03.TitlesBean.getTitles(TitlesBean.java:19)
at org.apache.jsp.ch05.books_jsp._jspService(books_jsp.java:103)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)代码如下:
titlesQuery = connection.prepareStatement("select isbn,title,editionNumber," + "copyright,publisherID,imageFile,price" + "from titles order by title");
book.setISBN(results.getString("isbn"));
book.setTitle(results.getString("title"));
book.setEditionNumber(results.getInt("editionNumber"));
book.setCopyright(results.getString("copyright"));
book.setPublisherID(results.getInt("publisherID"));
book.setImageFile(results.getString("imageFile"));
book.setPrice(results.getDouble("price"));
对应数据库里的表create table titles(
isbn varchar(20) primary key,
title varchar(100),
editionNumber int,
copyright varchar(20),
publisherID int,
imageFile varchar(20),
price numeric(9)
)
试试。
完整代码贴出来
是不是查询的时候列名写错了?
isbn varchar(20) primary key,
("select isbn,title,editionNumber
是不是isbn这个列的问题,ISBN。看看javabean
还是看不出来有什么问题?数据库中的表是正常的,可以查询出来的啊ISBN 是我封装书这个对象时,定义的字符串以下是在数据库里表查询的结果1 数据库原理 1 1 1 数据库原理 1
2 数据库原理 2 2 2 数据库原理 1
3 数据库原理 3 3 3 数据库原理 1
4 数据库原理 4 4 4 数据库原理 1
5 数据库原理 5 5 5 数据库原理 1
数据库中有isbn列
titlesQuery = connection.prepareStatement("select isbn,title,editionNumber," + "copyright,publisherID,imageFile,price" + "from titles order by title");price" + "from之间注意下空格,这样子能查的出来?
完整代码如下:package y2javaee.sg.ch03;import java.sql.*;
import java.util.*;public class TitlesBean {
private Connection connection;
private PreparedStatement titlesQuery;
private ResultSet results;
//返回BookBeans列表
public List getTitles() {
List titlesList = new ArrayList();
//获取书籍列表
connection = ConnectionManager.getConnection();
try {
titlesQuery = connection.prepareStatement("select isbn,title,editionNumber," + "copyright,publisherID,imageFile,price" + "from titles order by title");
//"select * from titles order by title"
results = titlesQuery.executeQuery();
//读取数据行
while(results.next()){
BookBean book = new BookBean();
String isbn = results.getString("isbn").trim();
book.setISBN(isbn);
book.setTitle(results.getString("title"));
book.setEditionNumber(results.getInt("editionNumber"));
book.setCopyright(results.getString("copyright"));
book.setPublisherID(results.getInt("publisherID"));
book.setImageFile(results.getString("imageFile"));
book.setPrice(results.getDouble("price"));
titlesList.add(book);
}
} catch (SQLException e) {
e.printStackTrace();
}finally {
ConnectionManager.closeResultSet(results);
ConnectionManager.closeStatement(titlesQuery);
ConnectionManager.closeConnection(connection);
}
return titlesList;
}
}
titlesQuery = connection.prepareStatement("select isbn,title,editionNumber," + "copyright,publisherID,imageFile,price" + "from titles order by title");修改为
titlesQuery = connection.prepareStatement("select isbn,title,editionNumber," + "copyright,publisherID,imageFile,price" + " from titles order by title");在红色的from前面加个空格
你使用getString("ISBN")可能就对了。