小弟新学jsp,这有什么错吗?

pwtitle 2005-01-22 04:29:39
package biz.gogomobile;

import java.sql.*;
import javax.sql.*;
import javax.naming.*;
import java.io.*;
import java.lang.String;

public class Base
{
private Connection conn = null;

public void Base(){
try{
String url = "jdbc:mysql://localhost/cmsc";
Class.forName("org.gjt.mm.mysql.Driver");
this.conn = DriverManager.getConnection(url,"root","");
}catch(ClassNotFoundException e){
System.err.println("ClassNotFoundException:" + e.getMessage());
}catch(SQLException e){
System.err.println("SQLExceptin:" + e.getMessage());
}catch(Exception e){
System.err.println("Exce:" + e.getMessage());
}
}

public String getTitle(int ID){
String title = "";
String sql = "select title from art_head where artid=" + ID;
try{
Statement st = this.conn.createStatement();
ResultSet rs = st.executeQuery(sql);
title = rs.getString("title");
}catch(SQLException e){
System.err.println("SQLExection:" + e.getMessage());
}catch(Exception e){
System.err.println("getTitle:" + e.getMessage());
}
return title;
}

};



对应的就jsp文件为:
<%@ page import="biz.gogomobile.Base" %>
<%
Base b = new Base();
String name = b.getTitle(27019);
out.println(name);
%>

控制台信息为:
2005-1-22 16:27:55 org.apache.catalina.core.StandardContext reload
ÐÅÏ¢: Reloading this Context has started
getTitle:null
getTitle:null

谁能告诉我这是怎么了?
p.s sql语句是没有错误的。

...全文
53 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
qiyongjun2003 2005-01-22
  • 打赏
  • 举报
回复
while(rs.next())
title = rs.getString("title");
vgvg 2005-01-22
  • 打赏
  • 举报
回复
ResultSet rs = st.executeQuery(sql);
while(rs.next())
title = rs.getString("title");

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧