Java 怎么将数据库里的数据显示到文本域
publicstaticStringjilu(intusername){Connectioncon=null;PreparedStatementstmt=null;Res...
public static String jilu(int username)
{
Connection con=null;
PreparedStatement stmt=null;
ResultSet rs=null;
try {
con=JdbcUtils.getConnection();
String sql="select oi and time from jilu where userid=?";
stmt=con.prepareStatement(sql);
rs=stmt.executeQuery(sql);
while(rs.next())
{
System.out.println(rs.getInt("userid")+" "+rs.getInt("oi")+" "+rs.getInt("time"));
}
}catch(Exception e) {
e.printStackTrace();
}
finally {
JdbcUtils.close(rs, stmt, con);
}
return ;
}
我要使 userid,oi,time显示到文本域
JTextArea textarea=new JTextArea(Jdbc.jilu(Zhu.i));
textarea.setEditable(false);
textarea.setLineWrap(true);
textarea.setFont(new Font(null,Font.PLAIN,18));
JScrollPane scrollPane = new JScrollPane(
textarea,
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER
);
jf.setContentPane(scrollPane);
这是文本域的部分代码 展开
{
Connection con=null;
PreparedStatement stmt=null;
ResultSet rs=null;
try {
con=JdbcUtils.getConnection();
String sql="select oi and time from jilu where userid=?";
stmt=con.prepareStatement(sql);
rs=stmt.executeQuery(sql);
while(rs.next())
{
System.out.println(rs.getInt("userid")+" "+rs.getInt("oi")+" "+rs.getInt("time"));
}
}catch(Exception e) {
e.printStackTrace();
}
finally {
JdbcUtils.close(rs, stmt, con);
}
return ;
}
我要使 userid,oi,time显示到文本域
JTextArea textarea=new JTextArea(Jdbc.jilu(Zhu.i));
textarea.setEditable(false);
textarea.setLineWrap(true);
textarea.setFont(new Font(null,Font.PLAIN,18));
JScrollPane scrollPane = new JScrollPane(
textarea,
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER
);
jf.setContentPane(scrollPane);
这是文本域的部分代码 展开
展开全部
用JTable创建表格,然后向表格中导入数据,你要先建个与数据库链接的类,然后执行查找语句,向表格导入数据
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Jdbc.jilu(Zhu.i) 这个没有设置返回值,改写如下:
public static String jilu(int username)
{
String resultStr = "";
Connection con=null;
PreparedStatement stmt=null;
ResultSet rs=null;
try {
con=JdbcUtils.getConnection();
String sql="select oi and time from jilu where userid=?";
stmt=con.prepareStatement(sql);
rs=stmt.executeQuery(sql);
while(rs.next())
{
resultStr = rs.getInt("userid")+" "+rs.getInt("oi")+" "+rs.getInt("time");
resultStr = resultStr + "\n";
}
}catch(Exception e) {
e.printStackTrace();
}
finally {
JdbcUtils.close(rs, stmt, con);
}
return resultStr ;
}
resultStr 就是你要文本域里面设置值的参数。
public static String jilu(int username)
{
String resultStr = "";
Connection con=null;
PreparedStatement stmt=null;
ResultSet rs=null;
try {
con=JdbcUtils.getConnection();
String sql="select oi and time from jilu where userid=?";
stmt=con.prepareStatement(sql);
rs=stmt.executeQuery(sql);
while(rs.next())
{
resultStr = rs.getInt("userid")+" "+rs.getInt("oi")+" "+rs.getInt("time");
resultStr = resultStr + "\n";
}
}catch(Exception e) {
e.printStackTrace();
}
finally {
JdbcUtils.close(rs, stmt, con);
}
return resultStr ;
}
resultStr 就是你要文本域里面设置值的参数。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询