javabean封装数据库问题
我将数据库封装在javabean里 再从jsp输出 但是什么都显示不出来 jsp:
<%@page contentType="text/html;charset=gb2312"%>
<%@page pageEncoding="gb2312"%>
<%request.setCharacterEncoding("gb2312");%>
<%@page import="my02.*"%>
<%@page import="java.util.*"%>
<jsp:useBean id="mydb" scope="session" class="my02.MyDbGet"/>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>my02</title>
</head>
<body>
<center>test</center>
<%
ArrayList array=mydb.talk();
for(int i=0;i<array.size();i++)
{
Speak speak=(Speak)array.get(i);%>
<%=speak.getName()%>
<%=speak.getTalk()%>
<%=speak.getTime()%>
<%}%>
</body>
</html>
db封装:
package my02;
import java.sql.*;
import java.io.*;
import java.util.*;
public final class MyDB
{
private static String durl="jdbc:mysql://localhost:3306/mytalk?user=root&password=iloveyy" +
"&useUnicode=true&charcterEncoding=gb2312";
private static Connection conn=null;
private ArrayList array;
public MyDB()
{
try
{
Class.forName("com.mysql.jdbc.Driver");
}
catch(ClassNotFoundException e)
{
System.out.println(e);
}
try
{
conn=DriverManager.getConnection(durl);
}
catch(SQLException e)
{
System.out.println(e);
}
}
public void remove()
{
try
{
conn.close();
}
catch(SQLException e)
{
System.out.println(e);
}
}
public ArrayList talk()
{
array=new ArrayList();
try
{
String str="select name,talk,time"+"from my02";
PreparedStatement prepStmt=conn.prepareStatement(str);
ResultSet rs=prepStmt.executeQuery();
while(rs.next())
{
String str1=rs.getString(1);
String str2=rs.getString(2);
String str3=rs.getString(3);
Speak speak=new Speak(str1,str2,str3);
array.add(speak);
}
prepStmt.close();
}
catch(Exception e)
{
System.out.println(e);
}
return array;
}
}
package my02;
/**
*
* @author root
*/
public class Speak
{
private String name;
private String talk;
private String time;
public Speak(String name,String talk,String time)
{
this.name=name;
this.talk=talk;
this.time=time;
}
public String getName()
{
return this.name;
}
public String getTalk()
{
return this.talk;
}
public String getTime()
{
return this.talk;
}
}
package my02;
import java.util.*;
public class MyDbGet
{
private MyDB mydb=null;
public MyDbGet()
{
try
{
this.mydb=new MyDB();
}
catch(Exception e)
{
System.out.println(e);
}
}
public ArrayList talk() throws Exception
{
return mydb.talk();
}
}