Read the database error ()

Category: Java SE
 
linzi_a010
2013-08-20 04:39:59

Sponsored Links
Wrote a very simple bean read database, run time is always error: invalid column name: prodimage. Said there is no this field, but I set a breakpoint when running watch, which is the result rs can see the collection to this field, and calls the bean jsp display can also display partially correct information, what is why ah? And sometimes read inside the database fields will appear getInt (), getString () functions such as error.

Sponsored Links

gujian0722
2013-08-20 04:53:41
not so weird it
erthjk
2013-08-20 05:11:23
you what database?

portion of the code look at it on a post
wangjy1226
2013-08-20 05:16:48
proimage blog fields?
benny5373
2013-08-20 05:28:14
My database is using sql server 2000, prodimage field is defined as varchar (200), which are written in the picture relative path string.
code is as follows:
connect to the database bean file Data.java:
package test.bean;

import java.sql. *;
import java.lang. *;
import java.io. *;
import java.util. *;

public class Data {
String strDbDriver = "com. microsoft.jdbc.sqlserver.SQLServerDriver ";
String url =" jdbc: microsoft: sqlserver :/ / localhost: 1433; DatabaseName = test ";
String user =" sa ";
String password = "1";
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;

public database () {
try {
Class.forName (strDbDriver);
}
catch (ClassNotFoundException e) {
System.err.println (" ; error! database (): "+ e.getMessage ());
}
}

public ResultSet executeQuery (String sql) {
rs = null;
try {
conn = DriverManager.getConnection (url, user, password);
stmt = conn.createStatement (ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
rs = stmt.executeQuery (sql);
}
catch (SQLException e) {
System.err.println ("error! Query:" + e.getMessage ()) ;
}
return rs;
}

public void close () {
try {
if (rs! = null) {
rs.close ();
}
if (stmt! = null) {
stmt.close ();
}
if (conn! = null) {
conn.close ();
}
}
catch (SQLException e) {
System.err.println (" database close error! ");
}
}
}

invoke the bean class display.java:
package test. bean;

import java.sql. *;

import test.bean. *;

public class Display {
ResultSet rs = null;
Data DBS = new Data ();

public Display () {}
public ResultSet getData () {
rs = DBS.executeQuery ("select * from tbTest");
return rs;
}
}

display effects jsp file List.jsp:
<% @ page contentType = "text / html; charset = UTF-8"%>
<% @ ; page import = "test.bean.Display"%>
<% @ page import = "java.sql. *"%>
<html>
<head> </head>
<body>
<table>
<%
Display Disp = new Display ();
ResultSet rs = Disp.getData ();
while (rs.next ())
{
out.println ("<TR> <TD> <img src = '" + rs1.getString ( "prodPic") "'> <br>" </TD> </TR> <br> ");
}
%>
</table>
</body>
</html>
gstwblsbs
2013-08-20 05:33:43
rs1.getString ( "prodPic") goes tbTest table you must have prodpic this field.
zozowell
2013-08-20 05:51:57
OK table has prodPic field?
zhangpengqian
2013-08-20 06:05:51
sometimes mistakes sometimes do not mistake it

jdbc connect to the database that could be a problem sometimes cause network problems such connections are not Database
pigsuzy
2013-08-20 06:23:12
too strange, the landlord to determine the table pro .. field?
d068062512
2013-08-20 06:39:08
that you do not use the field name, the serial number removed using field data to see rs1.getString (n ....)
wbausten123
2013-08-20 06:51:17
Cattle
put your hair up table and the code look
karmaangle
2013-08-20 07:04:42
database does have prodpic field, I also used to write a value into sql ah. has not been OK ah, if the subscript to fetch data, then there will be little problem is this: In a jsp pages read twice tbTest table, reading table were different fields, then if the first Reading, reading the second field rs1.getString (2), the second read when we read the third field rs1.getString (3), set breakpoints watch what rs1.getString (3), the result is actually the program execution or when used rs1.getString (2) it. (Saotou ....... puzzled .........)
wanglingyu1998
2013-08-20 07:07:43
Table to how fat ah?
Domain and server ip had changed since 8/23/2013. Suspend the user registration and posts for program maintenance.