File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes about jsp and mysql database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Reply locked New topic

about jsp and mysql database

amanda wu

Joined: Mar 16, 2003
Posts: 25
the following code runs always give an exception
saying: first name
java.sql.SQLException: Column 'f' not found.
however, the mysql database content shown is:
mysql> select * from employees;
| f |
| 1 |
| 2 |
2 rows in set (0.02 sec)

any expert pls spend me a min for it,
since i have spend a whole day examing it.
thanks a lot!!
<html><head><title><Employee List</title></head>
<%@ page import ="java.sql.*" %>
<table border =1 width= "75%">
<tr><th>first name</th></tr>
Connection conn=null;
Statement st=null;
ResultSet rs=null;
rs=st.executeQuery("Select * from employees");
<tr><td><%=rs.getString("f") %></td>
} catch (Exception ex){
wrong again:
if (rs!=null) rs.close();
if (st!=null) st.close();
if (conn!=null) conn.close();

Joined: Mar 20, 2003
Posts: 13
firstly describe the column name in a table using
describe <tablename>
Mysql does not accept short name and spaces between a word like 'First name'. In fact every database should accept a word without any space.
after getting the column name, u can use that particular column name. or u can use integer value which specifies its position in a column.
e.g if first column is First_Name then u can retrieve value using rs.getString(1);
if it does not help u then post again.
amanda wu

Joined: Mar 16, 2003
Posts: 25
many thanks to you,
it can print things out now,
but i input 1,2,3,4 in db,
the output is p,q,r,s,
do matter the it 1,2,3,4 is set as number or
as char..
can tell me why and how to solve it?
Don't get me started about those stupid light bulbs.
subject: about jsp and mysql database
It's not a secret anymore!