java操作数据库取值问题

[复制链接]
查看11 | 回复2 | 2011-3-15 23:36:58 | 显示全部楼层 |阅读模式
public String speciesname()

{

String speciesname = null;

Connection connect = null;

ResultSet result_sql = null;

try

{

Class.forName("com.mysql.jdbc.Driver");

connect = DriverManager.getConnection("jdbc:mysql://localhost/seo", "root", "root");

Statement statement_read = connect.createStatement();

result_sql = statement_read.executeQuery("select * from new_species");

while(result_sql.next())

{

speciesname = result_sql.getString("species_name");

}

}

catch (SQLException ex)

{

ex.printStackTrace();

}

catch (ClassNotFoundException ex)

{

ex.printStackTrace();

}

System.out.println(speciesname);

return speciesname;

}
我希望在while外面使用speciesname这个变量
求代码

回复

使用道具 举报

千问 | 2011-3-15 23:36:58 | 显示全部楼层
public Listspeciesname()
{
String speciesname = null;
List list = new ArrayList();//声明一个集合存放 speciesname
Connection connect = null;
ResultSet result_sql = null;
try
{
Class.forName("com.mysql.jdbc.Driver");
connect =
回复

使用道具 举报

千问 | 2011-3-15 23:36:58 | 显示全部楼层
什么问题
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行