runtime error:Invalid column name

runtime error:Invalid column name

Hello,

Can anyone please help me on this query? Programatically it is showing run time error. But in sql query the query is working fine.

import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; import java.util.ArrayList;

public class joinQuery {

public static ArrayList GetResults(){


    System.out.println("Getting Results!");

    String Query = null;
    ResultSet rs = null;
    Connection con = null;

    String dbUserName = "hr";
    String dbPassword = "hr";
    String url = "jdbc:oracle:thin:@192.168.0.56:1521:Oracle";
    String driver = "oracle.jdbc.OracleDriver";

    ArrayList list = new ArrayList();


    try{

    Class.forName(driver);
    con = DriverManager.getConnection(url, dbUserName, dbPassword);
    Statement st =con.createStatement();
    Query = "select t.TopicName, p.NumberofPolls from EMS_Topic t,EMS_Poll p where t.TopicID = p.TopicID and t.TopicName= 'Sybase' ";
    rs = st.executeQuery(Query1);
    while(rs.next()){

        list.add(rs.getString("1"));
        list.add(rs.getString("2"));

        System.out.println("Results:" +list);
    }
    }catch(Exception e){
        e.printStackTrace();
    }
    return list;

}

}

Console Output:

Getting Results! java.sql.SQLException: Invalid column name at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134) at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179) at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:269) at oracle.jdbc.driver.OracleStatement.getcolumnindex(OracleStatement.java:5971) at oracle.jdbc.driver.OracleResultSetImpl.findColumn(OracleResultSetImpl.java:1527) at oracle.jdbc.driver.OracleResultSet.getString(OracleResultSet.java:1482) at com.ibm.sample.joinQuery.GetResults(joinQuery.java:40) at com.ibm.sample.Result.main(Result.java:9)

SQL> desc EMS_Poll; Name Null? Type


POLLID NOT NULL NUMBER TOPICID NUMBER NUMBEROFPOLLS NUMBER(5) PSTARTDATE VARCHAR(20) PENDDATE VARCHAR(20)

SQL> desc EMS_Topic; Name Null? Type


TOPICID NOT NULL NUMBER CATEGORYID NUMBER TOPICNAME VARCHAR2(50) TOPICDESC VARCHAR2(150)

SQL editor output: SQL> select t.TopicName, p.NumberofPolls from EMSTopic t,EMSPoll p where t.TopicID = p.TopicID and t.TopicName= 'Sybase';

TOPICNAME NUMBEROFPOLLS


Sybase 0

View Answers









Related Tutorials/Questions & Answers:
runtime error:Invalid column name
runtime error:Invalid column name  Hello, Can anyone please help me...; } } Console Output: Getting Results! java.sql.SQLException: Invalid column name...(Result.java:9) SQL> desc EMS_Poll; Name
Altering a Column name in a table
Altering a Column name in a table  how to alter column name in MSSQL server 2005 the codesample given using "change" keyword alter table tablename change oldcolumnname to newcolumnnameADS_TO_REPLACE_1 is not working
Advertisements
how to Change column name and Make a unique column.
how to Change column name and Make a unique column.   how to Change column name and Make a unique column.   Hi, Following queries... a column- alter table [table name] change [old column name] [new column name
SQL Alter Column Name
SQL Alter Column Name       Alter Column Name in SQL is used to change or modify the name... The Tutorial explain you a simple example on SQL Alter Column Name
SQL Alter Column Name
SQL Alter Column Name       Alter Column Name in SQL is used to change or modify the name of column... you a simple example on SQL Alter Column Name. In this Example, create
Changing column name
Changing column name      ... the name of the column. As this is not the work of the programmer to change... the name of the column.  The name of the column of the column will be changed
Changing the Name of Column in a JTable
Changing the Name of Column in a JTable   ... the name of column in JTable component. You have learnt the JTable containing ... the name of column, you must have to change the column header. For changing the name
Change Column Name of a Table
Change Column Name of a Table   ... for renaming a column name in a database table. As we know that each table keeps contents in rows and column format. While making a table we specify the name
SQL get Column Name
SQL get Column Name       SQL get Column Name is used to return the Fieldnames of the table... an example from 'SQL get Column Name'. To understand and elaborate example we
Change Column Name in MySQL
.style1 { color: #0000FF; } Change Column Name in MySQL In this example How to change column name in MySQL. First of all we have created MySQL... Table name and change. The current column is named old_col but if you want
Display the column name using DBCP
;Columns Name: ");         ...;    System.out.println(col_name);     
How to copy existing column along with data and column name into another existing table
How to copy existing column along with data and column name into another... and column name also into another existing table... For ex; TableA : Address email... way to copy both column name and data
Shorting Table View By Column Name
Shorting Table View By Column Name This tutorial explains how to shorting table view by column name from the database in JSP and Servlet. This example... view by column name. The code of "userdetails.jsp"  given below
Java example to get Object class name at runtime
Java example to get Object class name at runtime       java get Object class name In java there is a way that makes us enabled to get the object class name at runtime. It can
how to get values for same column name from two different tables in SQL
how to get values for same column name from two different tables in SQL  how to get values for same column name from two different tables in SQL???? column name is emp_id loacated in these two tables company,employee
Adding a New Column Name in Database Table
Adding a New Column Name in Database Table  ... that we have created a table and forgets to add some important column name... the connection, it takes table name, column name and it's data type and at last
Fix table's column's name row(1st row of the table) so that it does not move up when the table is scrolled up to view more rows below
Fix table's column's name row(1st row of the table) so that it does not move up... which contains the column's name also move. This creates trouble for the users to fill the data in the respective columns as the column name is visible(as it has
Mysql Alter Column
the existing column field name. Understand with ExampleADS_TO_REPLACE_1... for altering the column name of the table employee1:ADS_TO_REPLACE_5 The Query below is used to modify the table 'employee1' and change the name of column from
Name
Name  make a program that take a input from user in alphabet and show all the name of that character E.g User give character "B". The program shows all the human names which starts from B.   Java show all names
Rename column name of table using DBCP
Jdbc Get Column Names
Column like its field name and data type using meta Data. Understand... getColumnName( ) This return you the name of column... Jdbc Get Column Names      
How to Delete a column and Add a new column to database
a column- alter table [table name] drop column [column name]; for add a column in a table- alter table [table name] add column [new column name] varchar...How to Delete a column and Add a new column to database   How
column matrix
column matrix  columan wise total matrix
column matrix
column matrix  columan wise total matrix
rename the column in sql
rename the column in sql   How can i rename the column name in SQL
Blob column
Blob column  Hi all... How to store an excel file in Blob column? I m using oracle 11 g database
Column select
Column select   How i fetch Experience wise resume?   Create a column experience which consist of only two values either yes...;td>Name</td><td><input type="text" name="name" value="<
Mysql Add Column Number
; ALTER TABLE table_name ADD column_name column-definition... Mysql Add Column Number       Mysql Add Column Number is used to add the column to the existing table
Hibernate Column
This tutorial explains the concept of column annotation in hibernate
SQL Alter Column
The SQL ALTER Syntax is used to modify the table and add a column name... table_name ADD column_name column-definition SQL ALTER...SQL Alter Column      
ModuleNotFoundError: No module named 'column'
ModuleNotFoundError: No module named 'column'  Hi, My Python... 'column' How to remove the ModuleNotFoundError: No module named 'column'... to install padas library. You can install column python with following command
ModuleNotFoundError: No module named 'column'
ModuleNotFoundError: No module named 'column'  Hi, My Python... 'column' How to remove the ModuleNotFoundError: No module named 'column'... to install padas library. You can install column python with following command
SQL Add Column
;  ALTER TABLE table_name ADD column_name column... SQL Add Column       SQL Add Column is used to add a new column in the existing table
SQL Add Column
; ALTER TABLE table_name ADD column_name column-definition... SQL Add Column       SQL Add Column is used to add a new column in the existing table. Understand
sql add comment to column
sql add comment to column  Sql query to add comments to column
how to add new column before two column in sql.
how to add new column before two column in sql.  how to add new column in table before two column in sql.   Syntax of Alter table: ALTER TABLE table_name ADD column_name column-definition Suppose, we have a table
how to add new column before two column in sql.
how to add new column before two column in sql.  how to add new column in table before two column in sql.   Syntax of Alter table: ALTER TABLE table_name ADD column_name column-definition Suppose, we have a table
how to add new column before two column in sql.
how to add new column before two column in sql.  how to add new column in table before two column in sql.   Syntax of Alter table: ALTER TABLE table_name ADD column_name column-definition Suppose, we have a table
how to add new column before two column in sql.
how to add new column before two column in sql.  how to add new column in table before two column in sql.   Syntax of Alter table: ALTER TABLE table_name ADD column_name column-definition Suppose, we have a table
SQL Alter Column
TABLE table_name ADD column_name column-definition SQL... SQL Alter Column       SQL Alter Column modifies the existing table and add a column
SQL Add Column Position
The ALTER Table is used to modify table name 'table_name' and add a column.... The Syntax is given as :  ALTER TABLE table_name ADD column_name column-definition [ FIRST | AFTER col_name ] SQL Add Colum
Excel Column change
Excel Column change  How to change sequence of columns in Excel sheet through Java
SQL Add Column Int
in a table.ADS_TO_REPLACE_4 ALTER TABLE table_name ADD column_name... SQL Add Column Int       SQL Add Column Int is used to add new column, whose field data type
SQL Alter Column Default Value
SQL Alter Column Default Value       Alter Column Default Value in  SQL Server... specified column. The use of default value is specified when insert
Name unique
Name unique  I want to check whether the value which I give for the name textfield already exists in the database. In case if it exists , it should.... In other words, value for the name should be unique
Count number of characters in a column.
Count number of characters in a column.  I just need you suggestions. Am from Biology Back ground. I just need to find out number of characters in a column i.e, if i have a file with text in this manner ACGT GCTA GCTA i need
search for a name
search for a name  Search for a name Write a program to accept an array of names and a name and check whether the name is present in the array. Return the count of occurrence. Use the following array as input {?Dave?, ?Ann
class name
class name  what is the class name of circle.java   how do i complie my jdk file, what happen s if i put in the correct commands and it still does not complie, what do i do next
JavaScript Hide Table Column
JavaScript Hide Table Column...; In this section, we are going to hide a table column using JavaScript... allow the user to enter the column number they want to hide. For this, we have
SQL Add Column Int
. ALTER TABLE table_name ADD column_name column-definition SQL Add... SQL Add Column Int       SQL Add Column Int is used to add new column, whose field data type

Ads