通过拆分在文本框中显示结果集
public class Time extends javax.swing.JFrame {
/** Creates new form Time */
public Time() {
initComponents();
generate();
}
public void generate()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:timetable","sa","nish1990()");
String str="select c_name from course where sem_id=1";
Statement str1=con.createStatement();
ResultSet res1=str1.executeQuery(str);
// THIS THE RS PLACE
while(res1.next())
{
String s=res1.getString(1);
JOptionPane.showMessageDialog(this,s);
}
}
catch(SQLException e)
{
System.out.println("SQL Exception :: "+e.toString());
}
catch(Exception e)
{
System.out.println(e.toString());
}
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Time().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JTextField jTextField6;
private javax.swing.JTextField tf1;
private javax.swing.JTextField tf2;
// End of variables declaration
}
查看我的数据库包含这些信息:
C_NAME C 科博尔 MATH
它能够检索所有数据...我不知道如何在文本框中拆分和显示..
rs.getString(1) 包含 C Cobol n Math ... 那么你如何只用 C n 显示它 显示的每个项目
public class Time extends javax.swing.JFrame {
/** Creates new form Time */
public Time() {
initComponents();
generate();
}
public void generate()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:timetable","sa","nish1990()");
String str="select c_name from course where sem_id=1";
Statement str1=con.createStatement();
ResultSet res1=str1.executeQuery(str);
// THIS THE RS PLACE
while(res1.next())
{
String s=res1.getString(1);
JOptionPane.showMessageDialog(this,s);
}
}
catch(SQLException e)
{
System.out.println("SQL Exception :: "+e.toString());
}
catch(Exception e)
{
System.out.println(e.toString());
}
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Time().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JTextField jTextField6;
private javax.swing.JTextField tf1;
private javax.swing.JTextField tf2;
// End of variables declaration
}
SEE MY DATABASE CONTAINS THESE INFO :
C_NAME
C
COBOL
MATH
its able to retrieve all the data... i dont know how to split and display in text box..
rs.getString(1) contains C Cobol n Math ...
so how do u take just C n display it
each of the item n display
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
rs.getString(1) 包含 C Cobol n Math ...那么你如何将 C n 显示它的每个项目 n 显示 –
如果这就是您所要求的,那么就做这样的事情,
我猜您不喜欢标准化。如果是,那么您甚至不必拆分数据。
rs.getString(1) contains C Cobol n Math ... so how do u take just C n display it each of the item n display –
if that's what you're asking then do something like this
I'm guessing you are not a fan of normalization. if you are then you don't even have to split your data.