Trying to run a query

I'm trying to run a query in a JTextField and then have that query display the output in a JTable. When I try to use .getText() to store the query in a string I keep getting errors about SQLException. Can anyone lend me in hand in telling me what I'm doing wrong?
This is the error I get when the line below would say:
query=jtf.getText();
c:\java>java myguidemo
Exception in thread "main" java.sql.SQLException: Invalid SQL type
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java
:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java
:146)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java
:208)
at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:67)
at oracle.jdbc.driver.T4CStatement.executeForRows(T4CStatement.java:946)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStateme
nt.java:1169)
at oracle.jdbc.driver.OracleStatement.doScrollExecuteCommon(OracleStatem
ent.java:4044)
at oracle.jdbc.driver.OracleStatement.doScrollStmtExecuteQuery(OracleSta
tement.java:4196)
at oracle.jdbc.driver.OracleStatement.executeQuery(OracleStatement.java:
1280)
at myguidemo.<init>(myguidemo.java:39)
at myguidemo.main(myguidemo.java:106)
c:\java>
Here is what I have so far. I took out the oracle IP and login. This is a working version, but where query = "SELECT * ....." I would like that to get whatever is typed in the JTextField. Also button1-5 is supposed to display the entire table in the JTable just by clicking it. Right now I just have them to change background color to make sure they worked.
import javax.swing.*;
import javax.swing.table.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class myguidemo extends JFrame implements ActionListener{
          Connection connection;
          Statement stmt;
          String query;
          ResultSet results;
          ResultSetMetaData md;
          int numrows, numcols;
          AbstractTableModel dataModel;
          Object [][] data;
JTextField jtf;
JTable jtb;
JPanel jp;
JScrollPane jsp;
JButton button1, button2, button3, button4, button5;
public myguidemo() throws Exception{
          Class.forName( "oracle.jdbc.driver.OracleDriver" );
          connection = DriverManager.getConnection("jdbc:oracle:thin:@);
          jp = new JPanel();
          add(jp,BorderLayout.SOUTH);
jtb = new JTable();
add(jtb,BorderLayout.CENTER);
jtf = new JTextField();
add(jtf,BorderLayout.NORTH);
query = "SELECT * FROM PATIENT";
stmt = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
results = stmt.executeQuery(query);
md = results.getMetaData();
          numcols = md.getColumnCount();
          numrows = 0;
          while(results.next()) numrows++;
          results.beforeFirst();
          data = new Object[numrows][numcols];
          results.next();
          for(int i=0; i<numrows; i++){
               for(int j=1; j<=numcols; j++){
                    data[i][j-1] = results.getString(j);
               results.next();
dataModel = new AbstractTableModel(){
     public int getColumnCount() {return numcols;}
     public int getRowCount() {return numrows;}
     public Object getValueAt(int row, int col) {return data[row][col];}
jtf.addActionListener(this);
jtb = new JTable(dataModel);
jsp = new JScrollPane(jtb);
add(jsp);
button1 = new JButton("Doctor");
button2 = new JButton("Medication");
button3 = new JButton("Patient");
button4 = new JButton("Prescription");
button5 = new JButton("Supplier");
jp.add(button1);
jp.add(button2);
jp.add(button3);
jp.add(button4);
jp.add(button5);
button1.addActionListener(this);
button2.addActionListener(this);
button3.addActionListener(this);
button4.addActionListener(this);
button5.addActionListener(this);
setTitle("CSIT");
setSize(1280,720);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
public void actionPerformed(ActionEvent e){
if (e.getSource() == jtf){
     jtf.setText("");
if (e.getSource() == button1) jtb.setBackground(Color.RED);
if (e.getSource() == button2) jtb.setBackground(Color.GREEN);
if (e.getSource() == button3) jtb.setBackground(Color.BLUE);
if (e.getSource() == button4) jtb.setBackground(Color.ORANGE);
if (e.getSource() == button5) jtb.setBackground(Color.YELLOW);
public static void main(String args[]) throws Exception{
     new myguidemo();
Edited by: rizzo18 on Dec 12, 2009 1:46 PM
Edited by: rizzo18 on Dec 12, 2009 2:06 PM

I'm trying to run a query in a JTextField and then have that query display the output in a JTable.1. Write classes that only do JDBC. If there is any GUI code at all in them then it is wrong.
2. Test those classes and modify until they work.
3. Use those classes in your GUI code (other classes) to do what you want.
Questions about 1 and 2 go in this forum. Questions about 3 go into a GUI forum.
Use code tags when you post code.

Similar Messages

  • Trying to run a query on 10g database using vbscript

    Hi,
    We have recently upgraded from oracle 8 to 10g and have been very impressed with the superb performance. However, we use vbscript applications on occasions to connect to our DB using ADO which now no longer work:
    Set dbUser = CreateObject("ADODB.Connection")
    set rec = createObject("ADODB.Recordset")
    dbUser.ConnectionString = "Provider=OraOLEDB.Oracle;User Id=???;Password=???;"
    dbUser.Open
    rec.ActiveConnection = dbUser
    rec.Open "select CUSTOMER_SURNAME FROM OURTABLE.TBL_ORDERS"
    do until rec.EOF
         msgbox rec("CUSTOMER_SURNAME")     
         rec.movenext
    loop
    This table has thousands of records but when we run the query we only get 1 result. Does anybody have any thoughts as to why this might be?

    I'm trying to run a query in a JTextField and then have that query display the output in a JTable.1. Write classes that only do JDBC. If there is any GUI code at all in them then it is wrong.
    2. Test those classes and modify until they work.
    3. Use those classes in your GUI code (other classes) to do what you want.
    Questions about 1 and 2 go in this forum. Questions about 3 go into a GUI forum.
    Use code tags when you post code.

  • Error while trying to run Bex Query -------- Field symbol is not assigned.

    Hello Every body,
    I am facing the following error after giving some value in Selection screen and trying to run the Bex Query
    ERROR : Field symbol is not assigned.
    Thanks in advance,
    Praveen

    can u plz give details of variables, what it is build on and the value u r inputing,
    also is thr any dump.
    double click on the error message it shows u. it will give u the detailed error message. post that too

  • I run out of memory when trying to run a query

    I need help with a query. I am trying to extract Total Qty Sold ( and eventually get this data by month), but when I would run the query asking for QTY I get "System Out Of Memory". I removed that party of the query asking for Qty and posted what I came up with below. Any Help is greatly appreciated.
    SELECT T0.[ItemCode], T0.[ItemName], T1.[FirmName], T0.[CardCode], T0.[SuppCatNum], T2.[ItmsGrpNam], T0.[U_U_CMG_PROGRAM], T0.[U_U_CMG_CATEG], T0.[U_CMG_STATUS], T0.[U_CMG_STORES], T0.[U_CMG_COLOR], T0.[U_CMG_LOCAT], T0.[MinLevel], T0.[MinOrdrQty]
    FROM OITM T0  INNER JOIN OMRC T1 ON T0.FirmCode = T1.FirmCode INNER JOIN OITB T2 ON T0.ItmsGrpCod = T2.ItmsGrpCod

    Hi,
    Welcome you post on the forum.
    Try this fist:
    SELECT T0.ItemCode, T0.ItemName, T1.FirmName, T0.CardCode, T0.SuppCatNum, T2.ItmsGrpNam, T0.MinLevel, T0.MinOrdrQty
    FROM OITM T0
    INNER JOIN OMRC T1 ON T0.FirmCode = T1.FirmCode
    INNER JOIN OITB T2 ON T0.ItmsGrpCod = T2.ItmsGrpCod
    WHERE T0.ItemCode Like '[%0\]%'
    Thanks,
    Gordon

  • 'ORA-01722: Invalid Number' error while Running a Query

    Hi,
    I'm trying to run a query built on a DSO. The DSO has a field 'Start Date'. This Start Date InfoObject has a reference Char as 0DATE.
    This Start Field has blank values due to which I'm getting the ORA-01722 error. I came across many threads with same topic of discussion. As mentioned in one of the Threads I have written a program to update 'Start Date' with 00000000. The code wriiten is "UPDATE /BIC/AZ_MONINV00 SET /BIC/ZSTR_DTE = '00000000' where /BIC/ZSTR_DTE = ' '.
    Now when I see the data in the active data table of DSO the blank value is replaced with '00000000'.
    But If I right click on the DSO click on display data the 'Start Date' field is blank. And now the Query also gets executed without any error. But in the output of the query the 'Start Date' Field has "#" values.
    Can anyone suggest on how can I make these "#" values appear as 00000000 in the report?

    In this case, you have to write a macro to avoid # in Analyzer.
    Right Click-->Display Data will show data from Active table of DSO only.
    If you don't want to show any blank date values in the report, you can exclude in Filter in Query.

  • Problem in running the query on ODS

    Hi All,
    I have been trying to run the query which consists of only 25 fields and doen't contain much calculations and routines and trying to restrict even 7000 records.
    That too result in system failure reporting on storage parameters somtimes giving dump as well.
    Could you please suggest me the solution for this as this is urgent requirement.
    Thanks
    Suryam

    Hi,
    Are you using a filter / restrictions in the query,if So create a Secondary index which can be suitable(same order) to this filterations/restrictions.
    You can find the order in where cluase in the sql statement used in the query execution.you can see it in SM50.
    With rgds,
    Anil Kumar Sharma .P

  • Error running "crsctl query css votedisk"

    Hi all,
    I get "Parse error: 'css' is an invalid argument" when I'm trying to run "crsctl query css votedisk"
    Any ideas?
    Thanks,
    Igor.

    its only available from My oracle support site.
    access only available if you have CSI no,you will get once you purchased the support/product from oracle.
    https://support.oracle.com/CSP/ui/flash.html
    https://support.oracle.com/CSP/ui/faq_en.html#registration

  • Error message when trying to create any query

     
    I am trying to run a query on my sql server and get the following error message:
    "An error occurred while executing batch. Error message is: The directory name is invalid."
    how do I fix?

    With me it had indeed something todo with some temp files.
    Me and my colleague where logged on to a remote server (remote desktop connection), and on that server we were both using the sql management studio.
    Suddenly we both received the error "An error occurred while executing batch. Error message is: The directory name is invalid.".
    The solution for us was just logging out (ALL USERS) that were currently connected (with a remote desktop connection and that were working with the sql management studio) and afterwards logging back in. That solved it here.
    Regards
    Thomas

  • Error while running a Query on webi

    Hi Folks
    I just installed a BOBJ edge standard 3.1 and trying to configure and test it  the very first time, I have following issues if you can advise the solution., I would really appreciate.
    1. when i try to create a test query on Webi Rich Client and and run query, I get the follow messge:
    A databse error occured. The database error text is : [Microsoft] [ODBC Microsoft access driver] could not use (unknown);
    file already in use (WIS 10901)
    2. The other issue I have is that when i create a test query on the webi (infoview side) and try to run the query I dont see any result like column, rown or fields, all I see is a solid yellow block which I believe is because of kmissing Java connector. can you guys pls let me know if this is the reason I dont see the report or Is there any other reason for that.
    I would appreciate your help on this.
    Regards

    Hello,
    What type of database did you build your universe on? Access? SQL Server? or other? You would need to go into the universe you are trying to use for the report go into File, Parameters, and see what your connection is, and while you're there, click "test" to be sure it is working. If not, that is your problem. If it is, but the report still is not working, either way, you will need to go into Control Panel, Administrative Tools, Data Sources (ODBC) and set up a system DSN that links to the correct database. Again test it to be sure it works. Then make sure the universe has a connection that uses this same DSN. The report should run.
    Hope that helps.

  • User Was Not Found when trying to run SSRS report!

    I'm trying to run SSRS report (Custom Reports) for Dynamics CRM 2011. However, when I try to run the report from the Reporting Manager it errors out "User Was Not Found"!
    Here's the complete error log:'
    An error has occurred during report processing. (rsProcessingAborted)
    Query execution failed for dataset 'DSMain'. (rsErrorExecutingCommand)
    Microsoft.Crm.CrmException: An unexpected error occurred. System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]:
    User Was Not Found <OrganizationServiceFault xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/xrm/2011/Contracts"> <ErrorCode>-2147220969</ErrorCode> <ErrorDetails xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
    <KeyValuePairOfstringanyType> <d2p1:key>CallStack</d2p1:key> <d2p1:value xmlns:d4p1="http://www.w3.org/2001/XMLSchema" i:type="d4p1:string"> at Microsoft.Crm.ServerLocatorService.GetCrmUserId(Guid organizationId,
    String authenticationInfo) at Microsoft.Crm.Sandbox.SandboxHostSids.IsCallerAllowed(SandboxSdkContext requestContext, String&amp; expectedSidSddlForm, String&amp; callerSidSddlForm) at Microsoft.Crm.Sandbox.SandboxSdkListener.AuthenticateCaller(SandboxCallInfo
    callInfo, SandboxSdkContext requestContext, String operation) at Microsoft.Crm.Sandbox.SandboxSdkListener.Execute(SandboxCallInfo callInfo, SandboxSdkContext requestContext, String operation, Byte[] serializedRequest)</d2p1:value> </KeyValuePairOfstringanyType>
    </ErrorDetails> <Message>User Was Not Found</Message> <Timestamp>2014-05-09T21:37:02.5487525Z</Timestamp> <InnerFault i:nil="true" /> <TraceText i:nil="true" /> </OrganizationServiceFault>
    An unexpected error occurred.
    User Was Not Found

    Hello,
    Can you preview the report in Report Builder or Report Designer?
    Based on the error message, the issue may related to a invalid user account for the report data source credentials.Please verify the user account is valid and has sufficient permission to access CRM data source.
    You can refer to the following blog to troubleshooting CRM custom report rsProcessingAborted error:
    http://blog.simpletrees.com/2013/04/mscrm-and-dreaded-rsprocessingaborted.html
    Regards,
    Fanny Liu
    Fanny Liu
    TechNet Community Support

  • Running a query in a View Designer results in an error, but running the same query in a Query window works

    Hi everyone,
    Just as my title says, I have a query which I've written in a query window and it works perfectly.
    But when I try to add the query code into the view designer, it throws a Syntax error.
    Error in ON clause near '('.Unable to parse query text.
    Also, when running the query from the view designer (pressing red exclamation mark) I get a different error.
    SQL Execution Error.Executed SQL statement: SELECT Sku, ParentSku, UPC, ...Error Source: .Net SqlClient Data ProviderError Message: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
    Has anyone else experienced this and is there any workaround?
    I have tried to create the view with T-SQL (CREATE VIEW etc.), but when opening it in the view designer I get the error from the 1st image.
    Thank you,
    Radu

    Hi Radu,
    Yes, I have faced similar issue. I had a View and it was working totally fine but when once I opened it in via right click - View Design, it was giving parse error.
    Cause is that Query designer parse and executes the query without error but the way View designer works, it can't parse it.
    Later I ignored View desinger and just used T-SQL like CREATE/ALTER view.
    Workaround is to do right click on View - Script View as - CREATE To/ ATER To.
    Regarding Timeout error, again the issue with View designer which couldn't execute query in there and ended up with timeout error.
    If your SELECT query and SELECT * FROM YourView works fine in Query designer, you are good to go.
    Similar threads:
    View with errors still saved, and still works...
    Parsing error when creating view
    -Vaibhav Chaudhari

  • Database Error while running the query.

    Hi,
    While running the query in webi rich client i am having a "database error IES 10901 and WIS 10901" , it is showing that the data source name not found and default driver is not specified.
    I am trying to generate report from efashion universe which is in .unx format, same client version and universe is running fine on another machine (webi rich client).
    PS: The above mentioned universe is running fine on my BI launch pad, the problem is with webi rich client only.
    Please help!!

    Hi,
    Which Database your are using .
    As explained by Yuvraj You need to install driver for specific database .
    Ask for client or (your Database ) driver from administrator .
    After installation you can see your database Driver in following path
    Control Panel\System and Security\Administrative Tools\Data Sources (ODBC)
    See in Drivers Tab .
    If you are using oracle & client is install on your system then Check TNS Names File in NETWORK folder .

  • No Data Shown because an error occurred while running the query

    Discoverer 10gR2 using Plus on Firefox:
    I have one workbook. The first sheet summarizes by Vendor. Parameters are Type, Category, Vendor (all optional) and mandatory date range.
    The second sheet summarized by Vendor and Model. Parameters are Type, Category, Vendor, Model (all optional) and mandatory date range.
    All parameters except the extra "Model" are shared between the sheets.
    When I run the Vendor sheet, parameters pop up, I put in dates and leave the rest blank. Results display. Yeah!
    When I then run the Model sheet, parameters pop up again (because it has one more parameter). Dates carry forward, leave the rest blank. I get the error No Data Shown because an error occurred while running the query. Refreshing does not help.
    If I click back to the Vendor sheet, then come back to the Model sheet, no parameter screen and the query runs.
    Booooo.
    Have tried multiple DBs, multiple EULs, multiple underlying data sources, replacing the offending parameter with a whole new one, no difference.
    Has any body run into this behavior? Is there an answer?
    -- Ron Olcott, Business Intelligence Product Manager

    What about trying this. On the parameter definition, you have a section on the bottom left of the Parameters window, called "Do you want to allow different parameter values for each worksheet?". When you say in your posting that all but the Model parameter is shared, I assume you mean that you have set this section value to "Allow only one set of paratmeter values for all worksheets". Try setting this to "Allow different parameter values for each worksheet". See if that might make a difference for you. If that works, you may have to leave the option at this, as the lesser of your evils. From my limited experience, the "Allow only one set of parameter mvalues for all worksheets" is a bit flaky in how it works. So I pretty much have gone to always saying to allow different parameter values for each worksheet. Hope this helps a bit. If worse comes to worse, if you have not done so already, log a service request with support and see what they say. Good luck.
    John DIckey

  • How to run sql query in bat file in task schedular at every 10 seconds

    This is my sql script :
    DECLARE @countRows INT,
    @currDate DATE,
    @checkForTasks INT,
    @created_by_id INT,
    @gst_ID int;
    SET @currDate = Getdate()
    SET @countRows = (SELECT Count(*)
    FROM [dbo].[sd_gst_effective_table]
    WHERE isapplied = 0)
    IF @countRows > 0
    -- Check for those GST''s who are not applied yet : if they are greater than 0 then perform next task
    BEGIN
    SET @checkForTasks = (SELECT Count(*)
    -- Check is current date equals to task date or not
    FROM [dbo].[sd_gst_effective_table]
    WHERE effect_date = @currDate AND isapplied = 0)
    IF @checkForTasks > 0
    -- If current date = task date then perform this task
    BEGIN
    SET @created_by_id = (SELECT TOP 1 createdby FROM [dbo].[sd_gst_effective_table] WHERE effect_date = @currDate AND isapplied = 0)
    SET @gst_ID = (SELECT gst_id FROM [dbo].[sd_gst_effective_table] WHERE effect_date = @currDate AND isapplied = 0)
    -- STEP 1 :: InActivate the existing GST according to createdbyID
    UPDATE sd_gst_rate
    SET isactive = 0,
    inactivedate = Getdate()
    WHERE isactive = 1
    AND createdby = @created_by_id
    -- STEP 2 :: Activate the New GST according to implementation date and gstID
    UPDATE sd_gst_rate
    SET isactive = 1,
    activedate = Getdate()
    WHERE id = @gst_ID
    -- STEP 3 :: Inactivate the applied GST from sd_gst_effective_table
    UPDATE [dbo].[sd_gst_effective_table] SET isApplied = 1 WHERE gst_id = @gst_ID
    END
    END
    DECLARE @Text AS VARCHAR(100)
    DECLARE @Cmd AS VARCHAR(100)
    DECLARE @value nvarchar(1000);
    SET @value = (SELECT CONVERT(TIME,GETDATE()) AS HourMinuteSeconds);
    SET @Text = 'File Writed ' + @value
    SET @Cmd ='echo ' + @Text + ' > E:\AppTextFile.txt'
    EXECUTE Master.dbo.xp_CmdShell @Cmd
    This is resided in videos folder of windows , i have created a task schedular in windows 8.1 to run daily at every 10 seconds , but it is not working ... Please tell me how to deal with it.
    Please note : This sql query is running perfectly in sql server. Query have no errors. Please check whats wrong with my time schedular. I just want my schedular to run every 10 seconds regardless of date.

    Hi Emad,
    Is your script in a ".sql" file? May I know how you configure the schedule task action?
    Since you didn't mention how you configure the schedule task, can you confirm you have followed the below step correctly?
    Save your script in a ".sql" file.
    Create a ".bat" file and call the sql file above inside with
    sqlcmd.exe, you can reference
    here.
    Configure a schedule task to run the ".bat" file in a certain interval.
    Have you tried to run the script in you bat file in a standalone commandline window? Please post the script in your bat file, It can help to diagnose the issue.
    If you have any question, feel free to let me know.
    Eric Zhang
    TechNet Community Support

  • After I run a query can I get it to return the number of files matched and each individual file name?

    After I run a query can I get it to return the number of files matched and each individual file name?  I am trying to do a data mining routine and this would be helpful. 
    BBANACKI

    Hi bbanacki,
    Please have a look at the following code:
    Define your queries and then:
    oAdvancedQuery.ReturnType=eSearchFile
    oMyDataFinder.Results.MaxCount = iMaxNumberOfReturndElements
    Call oMyDataFinder.Search(oAdvancedQuery)
    Set oMyResults  = oMyDataFinder.Results
    If oMyResults.IsIncomplete Then
      msgbox "The first " & str(oMyResults.Count) & " files found"
    Else
      msgbox str(oMyResults.Count) & "  files found"
    End If
    for iLoop = 1 to oMyResults.Count
      Cell.Text = oMyResults(iLoop).Properties("Name").Value
      Cell.Text = oMyResults(iLoop).Properties("fullpath").Value
    next
    Greetings
    Walter

Maybe you are looking for

  • Run time error while doing PGI

    hi gurus while doing PGI i am experiencing run time error. the ERROR ANALYSIS says that " check doc number 49 in company code 1234 and fiscal year 2007. and correct the number range status if necessary". i'm confused. please guide how to rectify the

  • How do i make top bar font bigger for mini on 60" display

    I have my MINI on a 60" display. I know how to zoom on web pages & make my bottom bar icons bigger. Can I make the font size of the top bar (all other text) bigger? If so , where do I go?

  • How do you download youtube videos?

    i was wondering if there is a way to download youtube videos without downloading a bunch of generic software and malware? Thanks

  • Error on apps

    Whenever I try to send requests on games connected to Facebook, it comes back with "an error occurred please try again later". I've tried later, turned the iPad off completely and then back on, removed and reinstalled the apps and even went as far as

  • Help... Header columns unfreeze when entering data on iphone.

    I'm a college professor and am in the process of migrating my gradebook spreadsheets to numbers with the goal of being able to input grades on my iphone (which is most convenient since I always, always have my phone with me). Here's my problem... If