JTable which recieves ResultSet as a parameter

Hi,
I am a .Net Framework originated developer which now learning Java.
I want to develop a ResultSet taking class to show data on the JFrame, to achieve this, I extend JTable, wrote a new constructor to take ResultSet then transfer its rows and column names to a two-dimensinal and a one dimensional array then add as columns to JTable. But I am unable to find a method for late adding columns to JFrame....
The code fallows...
Any ideas??
class BSTablo extends JTable {
     ResultSet rs;
     String [] isimler;
     String[][] datalar;
     void BSTablo(ResultSet recSet) {
          rs = recSet;
          try {
               ResultSetMetaData rsmd = rs.getMetaData();
               int sutsayi = rsmd.getColumnCount();
               rs.last();
               int satsayi = rs.getRow();           rs.beforeFirst();
               isimler = new String[sutsayi];
               datalar = new String[satsayi][sutsayi];
               for(int a = 1; a <= sutsayi; a++){
                    isimler[a-1]=rsmd.getColumnName(a);
               for(int k=0; rs.next(); k++){
                    for (int i = 1; i<=sutsayi; i++) {
                         datalar[k][i-1]=rs.getString(i);
               // Silly
// this = new JTable(datalar,isimler);
// So what now??
     catch (Exception ex) {
}

Thanx for your response camikr,
but I do know about JTable constructor and finding row and column count but I want to encapsulate the overhead by placing these into an extended version of a JTable class...
To accomplish this goal I found the row/column counts create the arrays but then I have to pass these to JTable (not in constructor because I am doing this by overriding the super class' constructor - the JTable's - and I can not pass (data array/ colum name array) these at the bottom of the constructor. Because you know that if I have to override but also call the super class' constructor I must do this at the first line of the constructor...)
So this wasn't what I want...
Thanx any way...

Similar Messages

  • Which difference between a PChar parameter and OCIString parameter ?

    Hello, I have some questions concerning the external procedures under Oracle 9i :
    Which difference between a PChar parameter and OCIString parameter ?
    When does one use PChar?
    When does one use OCISstring?
    In a wrapper, can one declare a parameter with a default value?
    Thanks in advance.
    Laurent Dardenne

    The rows retrieved from the database are filtered, if you define
    a parameter. You can see the parameter conditions getting added
    to the SQL, when you view the sql with sql inspector.
    On the other hand, with the page item, the filtering does not
    take place at the database level but at the discoverer level.

  • Getting resultset from out parameter ref cursor

    hi,
    i have written one procedure which return one refcursor as out parameter.
    when i am calling that proceduer how can i retrive that resultsets in my current program.
    ex
    DECLARE
    type A is ref cursor;
    B A;
    x NUMBER :=0;
    BEGIN
    APPSEARCH(NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,B);
    FOR i in b
    loop
    x:= x+1;
    end loop;
    DBMS_OUTPUT.PUT_LINE('ANS '||x);
    END;
    but it is giving error
    please advice
    thanks
    siva

    Thanks alessandro,
    SQL> DECLARE
    2 type A is ref cursor;
    B A;
    3 4 C b%rowtype;
    5 d NUMBER;
    6 BEGIN
    7 APPSEARCH(NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,B);
    8 loop
    9 fetch b into c;
    10 exit when b%notfound;
    11 DBMS_OUTPUT.PUT_LINE('ANS '||c%rowcount);
    12 end loop;
    13 close b;
    14 END;
    15 /
    C b%rowtype;
    ERROR at line 4:
    ORA-06550: line 4, column 4:
    PLS-00320: the declaration of the type of this expression is incomplete or
    malformed
    ORA-06550: line 4, column 4:
    PL/SQL: Item ignored
    ORA-06550: line 9, column 17:
    PLS-00320: the declaration of the type of this expression is incomplete or
    malformed
    ORA-06550: line 9, column 4:
    PL/SQL: SQL Statement ignored
    ORA-06550: line 11, column 35:
    PLS-00320: the declaration of the type of this expression is incomplete or
    malformed
    ORA-06550: line 11, column 6:
    PL/SQL: Statement ignored
    i dont know how to transfer the resultset from the procedure refcursor out parameter to my local cursor variable please help

  • Web ADI Error when using column from table which can be NULL as parameter

    Hi
    We have a custom integrator which queries the records and downloads into excel sheet. There is parameter list attached to it. One of the parameter is on a field which can have NULL. When we try running the ADI , we are getting the error :
    Fatal error: Please have your system administrator view the bne.log file.
    java.lang.NullPointerException
    Please contact your support representative
    Please help.
    Regards,
    Pradeep.

    <BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by Stefan Misch ([email protected]):
    Yep - if you try:
    create unique index XAK2_A_ARTIKEL
    on A_ARTIKEL(CUST_ID, EXTERNAL_ID);
    I get error ORA-01452, because of duplicate keys. I verified, that within a each CUST_ID, there is no duplicate non-null EXTERNAL_ID, but there are lots of rows for each CUST_ID where EXTERNAL_ID is NULL.
    Thanks for your help.
    Stefan<HR></BLOCKQUOTE>
    Create a view on your table, that you will use for inserts.
    Then, create a trigger INSTEAD OF INSERT on your view. You can perform the checks for uniqueness in it...
    Hope this will help...
    Thomas.
    null

  • Which reciever capabilities for Atv2, 3d panasonic TV

    have panasonic HD 3D TV.was given an AtV2 but need new reciever. do I need to buy an airplay compatable reciever or can I use ATV2 to stream audio to my TV which will then use HDMI to send to reciever?

    The Apple TV will stream audio to your TV, although you'd be best connecting your receiver direct to the Apple TV than passing through the TV. You can use HDMI or optical.

  • How to print a report which is consist a paper parameter form

    Hi !
    I have created a report file with paper parameter form and also create a form. Now , when I try to run this form it display
    REP-0788: Warning: The value of restricted LOV parameter ppass is not among the selectable values.
         USER ID     (a combo box with data)
         PASSWORD (a combo box with data)
    After click on submit the query button window dispaly a message run successfuly,But it does not print the report's data, it prints only paper parameter contents.
    i.e. REP-0788: Warning: The value of restricted LOV parameter ppass is not among the selectable values.
         USER ID     (a combo box with data)
         PASSWORD (a combo box with data)
    I used the following codes
    PROCEDURE RUN_REPORT1(vc_reportoj Varchar2, vc_reportserver varchar2, vc_runformat varchar2,report_otherparam VARCHAR2, pvar varchar2) IS
    v_report_id Report_Object;
    vc_ReportServerJob VARCHAR2(100); /* unique id for each Reportrequest */
    vc_rep_status VARCHAR2(100); /* status of the Report job */
    vjob_id VARCHAR2(100); /* job_id as number only string*/
    vfilename varchar2(255);
    vport varchar2(50);
    hidden_action VARCHAR2(2000) :='';
    v_report_other VARCHAR2(4000) :='';
    i number (5);
    c char;
    c_old char;
    c_new char;
    BEGIN
    /* Get a handle to the Report Object itself. */
    v_report_id:= FIND_REPORT_OBJECT(vc_reportoj);
    SET_REPORT_OBJECT_PROPERTY(v_report_id,REPORT_FILENAME,name_in(':parameter.path') ||'\'||NAME_IN('CTL_REPORTS.REPORT_NAME'));
         if pvar = 'FILE' then
              vfilename := CLIENT_GET_FILE_NAME('c:\',null, 'All Files (*.*)|*.*|',SAVE_FILE);
              if vfilename IS NOT NULL THEN     
              SET_REPORT_OBJECT_PROPERTY(v_report_id,REPORT_COMM_MODE,SYNCHRONOUS);
              SET_REPORT_OBJECT_PROPERTY(v_report_id, REPORT_EXECUTION_MODE, RUNTIME);
         SET_REPORT_OBJECT_PROPERTY(v_report_id, REPORT_DESTYPE, FILE);
                   SET_REPORT_OBJECT_PROPERTY(v_report_id, REPORT_DESNAME, vfilename||'.rtf');
                   SET_REPORT_OBJECT_PROPERTY(v_report_id,REPORT_SERVER,vc_reportserver);
                   hidden_action := hidden_action ||'&report='||GET_REPORT_OBJECT_PROPERTY(v_report_id,REPORT_FILENAME);
    hidden_action := hidden_action||'&destype='||GET_REPORT_OBJECT_PROPERTY(v_report_id,REPORT_DESTYPE);
    hidden_action := hidden_action||'&desformat='||GET_REPORT_OBJECT_PROPERTY (v_report_id,REPORT_DESFORMAT);
    hidden_action := hidden_action ||'&userid='||get_application_property(username)||'/'||get_application_property(password)||'@'||get_application_property(connect_string);
    c_old :='@';
    FOR i IN 1..LENGTH(report_otherparam) LOOP
    c_new:= substr(report_otherparam,i,1);
    IF (c_new ='') THEN
    c:='&';
    ELSE
    c:= c_new;
    END IF;
    -- eliminate multiple blanks
    IF (c_old ='' and c_new ='') THEN
    null;
    ELSE
    v_report_other := v_report_other||c;
    END IF;
    c_old := c_new;
    end loop;
    hidden_action := hidden_action ||'&'|| v_report_other;
    hidden_action := 'http://127.0.0.1:8889/reports/rwservlet'||'?_hidden_server='||vc_reportserver|| encode(hidden_action);
    SET_REPORT_OBJECT_PROPERTY(v_report_id,REPORT_OTHER,'pfaction='||hidden_action||''||report_otherparam);
    -- run Reports
                   vc_ReportServerJob:=RUN_REPORT_OBJECT(v_report_id);
                   vjob_id := substr(vc_ReportServerJob,length(vc_reportserver)+2,length(vc_ReportServerJob));
    vc_rep_status := REPORT_OBJECT_STATUS(vc_ReportServerJob);
    IF vc_rep_status='FINISHED' THEN
    WEB.SHOW_DOCUMENT ('http://127.0.0.1:8889/reports/rwservlet/getjobid'||vjob_id||'?server='||vc_reportserver||'&_blank');
    ELSE
    message ('Report failed with error message '||vc_rep_status);
    END IF;
    ELSE
         RETURN;
    end if;
    This is the part of the procedure.

    See Viewing Pages in Printer Friendly Mode and Selecting a Printer Friendly Template for an Application
    Thanks,
    Vikram

  • ## A Simple VB Client which passes a String as parameter ##

    Hello Everybody,
    I am looking for a simple VB client that should be able to pass a String
    (not FML) to a tuxedo service. I have already seen the FML example. Help
    would be highly appreciated.
    Thank you
    Nadeem
    @8563

    Hello,
    Please refer to my posting "Re: VB6 client and Tuxedo".
    The sample can be easily modified for STRING instead of FML.
    HTH
    regards
    MS

  • Saving ResultSet Data From JTable

    Hi! I need help! I am using a JTable to display resultsets from an oracle database. I am retrieving the columns and rows from the DB and putting them into vectors. Then I return the table and display it in a JScrollpane. I have a button which searches the db table for my query and fills the JTable with the results. Now, I am trying to save that result using a JFileChooser or some form of saving method. Does anyone have any idea how I could do this? Thanks.

    The JFileChooser will only give you a dialog that asks the user for a filename, it doesn't do the saving for you.
    Your question belongs into the swing or general programming category, since the database portion is all working, but here's a hint:
    You are trying to pull the data out of the table and save it to the file. Create a FileOutputStream for the filename the user choses in the file-choser, then iterate the rows and columns of the table (or the table's model (look at the JTable.getModel() method) and write the values to the file, maybe separated by commas and each row terminated by a carriage-return/linefeed combination.
    This should give you a nice CSV file (that can be read by Excel) containing the data that is in your table.

  • JTable and ResultSet TableModel with big resultset

    Hi, I have a question about JTable and a ResultSet TableModel.
    I have to develop a swing JTable application that gets the data from a ResultSetTableModel where the user can update the jtable data.
    The problem is the following:
    the JTable have to contain the whole data of the source database table. Currently I have defined a
    a TYPE_SCROLL_SENSITIVE & CONCUR_UPDATABLE statement.
    The problem is that when I execute the query the whole ResultSet is "downloaded" on the client side application (my jtable) and I could receive (with big resultsets) an "out of memory error"...
    I have investigate about the possibility of load (in the client side) only a small subset of the resultset but with no luck. In the maling lists I see that the only way to load the resultset incrementally is to define a forward only resultset with autocommit off, and using setFetchSize(...). But this solution doesn't solve my problem because if the user scrolls the entire table, the whole resultset will be downloaded...
    In my opinion, there is only one solution:
    - create a small JTable "cache structure" and update the structure with "remote calls" to the server ...
    in other words I have to define on the server side a "servlet environment" that queries the database, creates the resultset and gives to the jtable only the data subsets that it needs... (alternatively I could define an RMI client/server distribuited applications...)
    This is my solution, somebody can help me?
    Are there others solutions for my problem?
    Thanks in advance,
    Stefano

    The database table currently is about 80000 rows but the next year will be 200000 and so on ...
    I know that excel has this limit but my JTable have to display more data than a simple excel work sheet.
    I explain in more detail my solution:
    whith a distribuited TableModel the whole tablemodel data are on the server side and not on the client (jtable).
    The local JTable TableModel gets the values from a local (limited, 1000rows for example) structure, and when the user scroll up and down the jtable the TableModel updates this structure...
    For example: initially the local JTable structure contains the rows from 0 to 1000;
    the user scroll down, when the cell 800 (for example) have to be displayed the method:
    getValueAt(800,...)
    is called.
    This method will update the table structure. Now, for example, the table structure will contain data for example from row 500 to row 1500 (the data from 0 to 499 are deleted)
    In this way the local table model dimension will be indipendent from the real database table dimension ...
    I hope that my solution is more clear now...
    under these conditions the only solutions that can work have to implement a local tablemodel with limited dimension...
    Another solution without servlet and rmi that I have found is the following:
    update the local limited tablemodel structure quering the database server with select .... limit ... offset
    but, the select ... limit ... offset is very dangerous when the offset is high because the database server have to do a sequential scan of all previuous records ...
    with servlet (or RMI) solution instead, the entire resultset is on the server and I have only to request the data from the current resultset from row N to row N+1000 without no queries...
    Thanks

  • Which view corresponds to a JTable?

    Is there anyway you can ask a JTable which View it's bound to??
    I want to do this because i want to implement a copy/paste feature in my application.
    If the user chooses a row in a table (there are multiple table's on a form, hence the question) and presses the copy button in the toolbar i want to copy the chosen row in the focused table.
    Regards
    Johan

    You should know the approximate time by which you have dropped the table. You can use the time to recover or can get the SCN from smon_scn_time.
    Thanks and Regards,
    Satheesh Babu.S
    Bangalore.

  • Printing JTable

    Hi
    I ahve created a print method in order to print various reports. However, This is set up to print results of queries. One of the reports that I wish to report is a lot more complicated than just a query...and realistically I need to print a JTable, which displays the result of some calculations.
    Ive tried just passing a JTable instead of a query as the parameter, however as you will see below, what I set up to print is a TextArea that appends text. Due to this I cannot simply append the JTable. I was wondering, is there a way of printing this JTable. Code as follows:
    public PrintMortgageSearch(String query) {
            super("Printing Result of Search", false, true, false, true);
            //for getting the graphical user interface components display area
            Container cp = getContentPane();
            //for setting the font
            textArea.setFont(new Font("Tahoma", Font.PLAIN, 9));
            //for adding the textarea to the container
            cp.add(textArea);
            try {
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                con = DriverManager.getConnection(url, "myLogin", "myPassword");
            catch (ClassNotFoundException ea) {
                System.out.println(ea.toString());
            catch (Exception e) {
                System.out.println(e.toString());
            try {
                statement = con.createStatement();
                resultset = statement.executeQuery(query);
                textArea.append("=============== Results of Search ===============\n\n");
                while (resultset.next()) {
                    textArea.append("Lender: " + resultset.getString(1) + "\t" +
                    "Product: " + resultset.getString(2) + "\t" +
                    "Term: " + resultset.getString(3) + "\t" +
                    "Rate: " + resultset.getString(4) + "\t" +
                    "APR: " + resultset.getString(5) + "\t" +
                    "Cost: " + resultset.getString(6) + "\t"+"\n\n");
                textArea.append("=============== Results of Search ===============");
                resultset.close();
                statement.close();
                con.close();
            catch (SQLException SQLe) {
                System.out.println(SQLe.toString());
            //for setting the visible to true
            setVisible(true);
            //to show the frame
            pack();
        }Id like to just append the JTable to the TextArea rather than using the DB connection as above.
    Is this possible?
    Thanking you in advance

    Actually, Im having a problem!
    The JTable doesnt fit on the page.
    Ive tried adjusting the
    paper.setImageableArea(0, 0.5D*72, 4.267D*72, 10.652D*72);
           paper.setSize(6.267D*72, 11.692D*72);these figures are reduced on what it was previously...but everytime I lower the width and height figures theres no difference in the size at all!
    Does anyone know what exactly it is that I have to change

  • How to retrieve the outer parameter of a stored procedure in XSQL page

    I have to call a stored procedure in the xsql page that returns a resultset (ie. oracle table/record type) through an outer paramter. Is there any built-in xsql action tag available to get the parameter and present
    it in xml on the page? please help, thanks.

    You cant get two resultsets out of SP like this. The workaround is to merge and bring the resultsets.
    For this number of columns as well as corresponding datatypes have to be compatible. Also you will need one additional column which indicates resultset value. Then use this as filter to get your desired resultset out
    create procedure GetData as
    begin
    select 'resultset1' as Cat,*,.. N columns from Emp
    union all
    select 'resultset2' as Cat,*,.. N columns from Dept
    end
    create table #tmp1 (Ddeptid int, deptname varchar(500),Location varchar(100))
    Insert into #tmp1 (Ddeptid , deptname ,Location )
    Select column1,column2,column3
    from OPENROWSET('SQLOLEDB','Data Source=Server_name;Trusted_Connection=yes;
    Integrated Security=SSPI','Execute yourdb..GetData')
    WHERE Cat = 'resultset1'
    create table #tmp (empid int , ename varchar(500),DeptId int , salary int)
    Insert into #tmp (empId,ename,deptId,salary)
    Select column1,column2,column3, column4
    from OPENROWSET('SQLOLEDB','Data Source=Server_name;Trusted_Connection=yes;
    Integrated Security=SSPI','Execute yourdb..GetData')
    WHERE Cat = 'resultset2'
    also see
    http://sqlblogcasts.com/blogs/madhivanan/archive/2007/11/26/select-columns-from-exec-procedure-name-is-this-possible.aspx
    Another method is to populate table with relevant resultset within procedure itself and then select from the table directly outside.
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Currently have JTextArea, but would like the output to be in a JTable...

    Hi there. I asked this question in the database section, but I ended up getting more questions and separating code, etc. Needless to say, my initial question went unanswered. So, for the purposes of this question, let me get this one thing out of the way:
    Yes, I know this is one big file, and that I should have the GUI and DB separated. However, this is for a small project that I'm working on, and for the moment, I'm not too worried about separating class files. As long as the program works as I want it too, so much the better for me.
    Now, on to the question at hand. Currently, I have a project that connects to a MySQL DB, and it displays the output from an SQL command in a JTextArea. It looks horribly ugly, as all the columns are not formatted properly. Take a look:
    http://img508.imageshack.us/img508/2193/testxe4.jpg
    Sure I can see columns, but I would love for the output to be displayed in a neat JTable, which is also much easier on the eyes.
    Here is the current code:
    package classes;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import java.sql.*;
    import java.util.*;
    public class SQLClient extends JApplet {
         private Connection connection;
         private Statement statement;
         private JTextArea jtasqlCommand = new JTextArea();
         private JTextArea jtaSQLResult = new JTextArea();
         JTextField jtfUsername = new JTextField();
         JPasswordField jpfPassword = new JPasswordField();
         JButton jbtExecuteSQL = new JButton("Execute SQL Command");
         JButton jbtClearSQLCommand = new JButton("Clear");
         JButton jbtConnectDB1 = new JButton("Connect to Database");
         JButton jbtClearSQLResult = new JButton("Clear Result");
         Border titledBorder1 = new TitledBorder("Enter a SQL Command");
         Border titledBorder2 = new TitledBorder("SQL Execution Result");
         Border titledBorder3 = new TitledBorder("Enter Database Information");
         JLabel jlblConnectionStatus1 = new JLabel("");
         JLabel jlblConnectionStatus2 = new JLabel("Not Connected");
         public void init() {
              JScrollPane jScrollPane1 = new JScrollPane(jtasqlCommand);
              jScrollPane1.setBorder(titledBorder1);
              JScrollPane jScrollPane2 = new JScrollPane(jtaSQLResult);
              jScrollPane2.setBorder(titledBorder2);
              JPanel jPanel1 = new JPanel(new FlowLayout(FlowLayout.RIGHT));
              jPanel1.add(jbtClearSQLCommand);
              jPanel1.add(jbtExecuteSQL);
              JPanel jPanel2 = new JPanel();
              jPanel2.setLayout(new BorderLayout());
              jPanel2.add(jScrollPane1, BorderLayout.CENTER);
              jPanel2.add(jPanel1, BorderLayout.SOUTH);
              jPanel2.setPreferredSize(new Dimension(100, 100));
              JPanel jPanel3 = new JPanel();
              jPanel3.setLayout(new BorderLayout());
              jPanel3.add(jlblConnectionStatus1, BorderLayout.CENTER);
              jPanel3.add(jbtConnectDB1, BorderLayout.EAST);
              JPanel jPanel4 = new JPanel();
              jPanel4.setLayout(new GridLayout(4, 1, 10, 5));
              jPanel4.add(jtfUsername);
              jPanel4.add(jpfPassword);
              JPanel jPanel5 = new JPanel();
              jPanel5.setLayout(new GridLayout(4, 1));
              jPanel5.add(new JLabel("Username"));
              jPanel5.add(new JLabel("Password"));
              JPanel jPanel6 = new JPanel();
              jPanel6.setLayout(new BorderLayout());
              jPanel6.setBorder(titledBorder3);
              jPanel6.add(jPanel4, BorderLayout.CENTER);
              jPanel6.add(jPanel5, BorderLayout.WEST);
              JPanel jPanel7 = new JPanel();
              jPanel7.setLayout(new BorderLayout());
              jPanel7.add(jPanel3, BorderLayout.SOUTH);
              jPanel7.add(jPanel6, BorderLayout.CENTER);
              JPanel jPanel8 = new JPanel();
              jPanel8.setLayout(new BorderLayout());
              jPanel8.add(jPanel2, BorderLayout.CENTER);
              jPanel8.add(jPanel7, BorderLayout.WEST);
              JPanel jPanel9 = new JPanel();
              jPanel9.setLayout(new BorderLayout());
              jPanel9.add(jlblConnectionStatus2, BorderLayout.EAST);
              jPanel9.add(jbtClearSQLResult, BorderLayout.WEST);
              this.add(jPanel8, BorderLayout.NORTH);
              this.add(jScrollPane2, BorderLayout.CENTER);
              this.add(jPanel9, BorderLayout.SOUTH);
              jbtExecuteSQL.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent e) {
              executeSQL();
              jbtConnectDB1.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent e) {
              connectToDB();
              jbtClearSQLCommand.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent e) {
              jtasqlCommand.setText(null);
              jbtClearSQLResult.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent e) {
              jtaSQLResult.setText(null);
         private void connectToDB() {
              String driver = "com.mysql.jdbc.Driver";
              String url = "jdbc:mysql://localhost:3306/petstore2002";
              String username = jtfUsername.getText().trim();
              String password = new String(jpfPassword.getPassword());
              try {
                   Class.forName(driver);
                   connection = DriverManager.getConnection(url, username, password);
                   jlblConnectionStatus2.setText("Connected To Database");
              catch (java.lang.Exception ex) {
                   ex.printStackTrace();
         private void executeSQL() {
              if (connection == null) {
                   jtaSQLResult.setText("Please connect to a database first");
                   return;
              else {
                   String sqlCommands = jtasqlCommand.getText().trim();
                   String[] commands = sqlCommands.replace('\n', ' ').split(";");
                   for (String aCommand: commands) {
                        if (aCommand.trim().toUpperCase().startsWith("SELECT")) {
                             processSQLSelect(aCommand);
                        else {
                             processSQLNonSelect(aCommand);
         private void processSQLSelect(String sqlCommand) {
              try {
                   statement = connection.createStatement();
                   ResultSet resultSet = statement.executeQuery(sqlCommand);
                   int columnCount = resultSet.getMetaData().getColumnCount();
                   String row = "";
                   for (int i = 1; i <= columnCount; i++) {
                        row += resultSet.getMetaData().getColumnName(i) + "\t";
                   jtaSQLResult.append(row + '\n');
                   while (resultSet.next()) {
                        row = "";
                        for (int i = 1; i <= columnCount; i++) {
                             row += resultSet.getString(i) + "\t";
                        jtaSQLResult.append(row + '\n');
              catch (SQLException ex) {
                   jtaSQLResult.setText(ex.toString());
         private void processSQLNonSelect(String sqlCommand) {
              try {
                   statement = connection.createStatement();
                   statement.executeUpdate(sqlCommand);
                   jtaSQLResult.setText("SQL command executed");
              catch (SQLException ex) {
                   jtaSQLResult.setText(ex.toString());
         public static void main(String[] args) {
              SQLClient applet = new SQLClient();
              JFrame frame = new JFrame();
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.setTitle("Interactive SQL Client");
              frame.getContentPane().add(applet, BorderLayout.CENTER);
              applet.init();
              applet.start();
              frame.setSize(800, 600);
              Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
              frame.setLocation((d.width - frame.getSize().width) / 2,
              (d.height - frame.getSize().height) / 2);
              frame.setVisible(true);
    }Right now it works fine, and I am planning on using this as an initial prototype for the presentation. Can I get some help on getting the output displayed into a JTable? How would I go abouts doing the conversion? I'm fairly new to Java (taking a course on it), and I'm worried that if I change one line of code the whole thing will get ruined and I'll need to start from scratch.

    -> It sounds like you're getting annoyed with the amount of people asking perfectly legitimate questions
    Your expectations are not legitimate. We attempt to understand your problem and give you the resources to solve the problem. Many times those resources are in the form of a tutorial or a reference to the API. We are not here to write code for you.
    I pointed you in the right direction. Its up to you do to some learning on your own. You have not made the slightest effort to understand how to use a JTable. You have not made the slightest effort to search the forum to see if you question has been asked before (it has).
    Your attitude and effort determines how much effort we make. Frankly you have made no effort whatsoever to solve you problem so as far as I am concerned you are on you own. Apparently I am not the only one who thinks you should be making more of an effort based on all the other advice you have received.

  • Re: Using JScrollPane With JTable

    >
    myNamePane.setVisible(true);This is meaningless, a component becomes visible by default when you add it to a visible container
    if(e.getSource().equals(newStudent))
           JFrame newFrame = new JFrame("Please select a student");
           newFrame.setContentPane(myNamePane);
           newFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
           newFrame.setResizable(false);
           newFrame.pack();
           newFrame.setVisible(true);
         }Which brings us to the main issue, you need to add the JScrollPane to you frame
    newFrame.add(myNamePane);Read the tutorial: [Using Top-Level Containers|http://java.sun.com/docs/books/tutorial/uiswing/components/toplevel.html]

    Hello Rodney,
    Thanks for the information and the tutorial.. I've worked with containers before but never got around to reading that one, which has clarified a few things for me.
    Unfortunately however, my problem persists. I obviously can't set the content pane as the JScrollPane and add it to the Frame, so rather than setting the JScrollPane as the content pane (which I did previously), I added it to the frame as you suggested:
    if(e.getSource().equals(newStudent))
         JFrame newFrame = new JFrame("Please select a student");
    //     newFrame.setContentPane(myNamePane);
         newFrame.add(myNamePane);
         newFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         newFrame.setResizable(false);
         newFrame.pack();
         newFrame.setVisible(true);
    }But the same thing happens! All I see is a new, empty JFrame. I feel like my understanding of the JScrollPane may be flawed, but I'm really not sure :/
    Edit: In fact, it is most definitely a problem either with my JTable or my JScrollPane. I used the setPreferredSize() method to check if the JScrollPane was being displayed in the JFrame, and it is. There is no JTable in the pane however.
    Edit #2: The problem was, in fact, with my JTable. The ResultSet I was using was TYPE_FORWARD_ONLY, and I was trying to call studentNameSet.first(), which prevented the JTable from ever being created. Thanks for your help, Rodney. Although I do have one more question.. Do you know a better way for me to find the number of student names given that ResultSet? I can't iterate through it twice as I had done earlier, so now for testing purposes I've simply hardcoded the number in, but I'd rather have the program find the total number of entries dynamically.
    Edited by: Pheer on Jul 22, 2008 10:07 AM
    Edited by: Pheer on Jul 22, 2008 10:09 AM

  • Different parameter usage causes problem

    Hi there,
    I am creating a report based on a sql query. Therefore I have to parameters to filter the query i.e. "SELECT * FROM Person WHERE Birthday >= {?StartDate} AND BirthDay <= {?EndDate}". Both parameters are defined as Date.
    This works so far. Then in the Field-Explorer I define a third parameter named "GroupName" which is dynamic and should be filled from the column "Groupname" of the resultset. This parameter is used to identify a leading group which is then separated from all the others.
    My problem now is that I am asked twice to input parameters. First those two I defined in the query using the database wizzard (StartDate, EndDate). Then I am asked a second time to input all the three parameters (StartDate, EndDate, GroupName) where the two first parameters where prefilled with what I entered before. But the list of groupname is not filled so I can not select one or multiple values.
    My questions are:
    - Why am I asked twice and not once including all three parameters
    - Why is group not filled in the parameter mask
    - Is this behavior by design and if yes how can I workaround
    This concerns Crystal Report 11 and 12.
    Thanks for every hint.
    Kind regards
    Patrick
    Edited by: Patrick Jox on Sep 18, 2008 9:06 AM

    Hi Patrick,
    I think in crystal if you create a parameter in command and then if you create a parameter from report then it will prompt twice. The only way is to create all the parameters in command or in report. Why you want to create a groupname parameter in report level but not in command?
    Regards,
    Raghavendra.G

Maybe you are looking for

  • Everytime my phone vibrates it makes this loud noise from inside that sounds like a weird cracking noise or something help!!

    Okay so I noticed a week or two ago that there was something lose on the inside of my iPhone 5s and ever since then when my phone vibrates sometimes there is this weird noise. It sounds almost like a cracking noise from the inside or a weird electric

  • I am looking for a word processing app

    I am looking for a word processing app that I can use for sending .doc and .docx format papers via email or uploading them to websites directly from my ipad 2 without having to export them to or sync them with my actual computer.  Does the Pages app

  • Report 3.0 runtime error

    Our Company has developed a financial Accounting Solution using Oracle and D2K.We had used reports 3.0 to build the reports . Once we install our package in a machine after a certain number of days certain reports are not displayed and the error in t

  • How to work even and odd number query

    Plz explain how below worked even and odd query 2 ) why used subquery after from and which time we can use(what time of out put) even select * FROM (SELECT ROW_NUMBER() OVER(ORDER BY stud_id) as row ,grno,stud_id from stud_Enrollment) d  WHERE d.row

  • Error: Filter Initialization Failed : trinidad

    I am working on the new Jdeveloper 11. And when i get this error as soon as i try to create a jspx page. Filter Initialization Failed : trinidad java.lang.NullPointerException      at org.apache.myfaces.trinidadinternal.skin.SkinUtils._registerSkinEx