通过拆分在文本框中显示的结果集

时间:2022-03-28 11:08:07
         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

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

rs.getString(1)包含C Cobol n Math ...所以你如何只用C n显示每个项目n显示

1 个解决方案

#1


0  

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

rs.getString(1)包含C Cobol n Math ...所以你如何只用C n显示每个项目n显示 - 如果这是你要求的那么做这样的事情

    String s;   

    while(res1.next()){
       s=res1.getString(1);
    }

  String [] splitted = s.split(" ");
   for(String aSplit: splitted){
        System.out.println(aSplit);
   }

I'm guessing you are not a fan of normalization. if you are then you don't even have to split your data.

我猜你不是正常化的粉丝。如果你那么你甚至不需要拆分你的数据。

#1


0  

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

rs.getString(1)包含C Cobol n Math ...所以你如何只用C n显示每个项目n显示 - 如果这是你要求的那么做这样的事情

    String s;   

    while(res1.next()){
       s=res1.getString(1);
    }

  String [] splitted = s.split(" ");
   for(String aSplit: splitted){
        System.out.println(aSplit);
   }

I'm guessing you are not a fan of normalization. if you are then you don't even have to split your data.

我猜你不是正常化的粉丝。如果你那么你甚至不需要拆分你的数据。