小弟新学jsp,这有什么错吗?
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语句是没有错误的。