Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

about jsp and mysql database

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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>
<body>
<%@ page import ="java.sql.*" %>
<table border =1 width= "75%">
<tr><th>first name</th></tr>
<%
Connection conn=null;
Statement st=null;
ResultSet rs=null;
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn=DriverManager.getConnection("jdbc:mysql://localhost/DB1");
st=conn.createStatement();
rs=st.executeQuery("Select * from employees");
while(rs.next()){
%>
<tr><td><%=rs.getString("f") %></td>
</tr>
<%
}
%>
</table>
<%
} catch (Exception ex){
ex.printStackTrace();
out.println(ex);
%>
</table>
wrong again:
<%
}finally{
if (rs!=null) rs.close();
if (st!=null) st.close();
if (conn!=null) conn.close();
}
%>
</body></html>
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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?
 
Sometimes you feel like a nut. Sometimes you feel like a tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
    Bookmark Topic Watch Topic
  • New Topic