runtime error:Invalid column name

Ads
 

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

Ads









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
SQL Alter Column Name
SQL Alter Column Name       Alter Column Name in SQL is used to change or modify the name... a simple example on SQL Alter Column Name. In this Example, create
Advertisements
SQL Alter Column Name
SQL Alter Column Name       Alter Column Name in SQL is used to change or modify the name of column... example on SQL Alter Column Name. In this Example, create a table 'Stu_Table
SQL get Column Name
SQL get Column Name       SQL get Column Name is used to return the Fieldnames of the table... get Column Name'. To understand and elaborate example we create a table 'stu
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
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... shorting  table view by column name. The code of "userdetails.jsp
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
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 Example The Tutorial illustrate...) Query for altering the column name of the table employee1: The Query below is used to modify the table 'employee1' and change the name of column from
Jdbc Get Column Names
Column like its field name and data type using meta Data. Understand with Example... describe you a code that explain you the column property  like field name...( ) This return you the name of column
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 the column in sql
rename the column in sql   How can i rename the column name in SQL
column matrix
column matrix  columan wise total matrix
column matrix
column matrix  columan wise total matrix
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="<
Blob column
Blob column  Hi all... How to store an excel file in Blob column? I m using oracle 11 g database
Mysql Add Column Number
; ALTER TABLE table_name ADD column_name column... Mysql Add Column Number       Mysql Add Column Number is used to add the column to the existing table
SQL Alter Column
and add a column name that you want to add and its data type. ALTER TABLE table_name ADD column_name column-definition...SQL Alter Column      
SQL Add Column Position
SQL Add Column Syntax The ALTER Table is used to modify table name 'table_name' and add a column at the specific position. The first column... TABLE table_name ADD column_name column-definition [ FIRST | AFTER col_name
SQL Add Column
as below:   ALTER TABLE table_name ADD column_name column-definition SQL Add Colum Query The given below... SQL Add Column      
SQL Add Column
as below:   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. Understand
SQL Alter Column Syntax
; ADD [COLUMN] col_name column_definition[FIRST | AFTER col_name ] : The Query... Name  | ADD [COLUMN] (col_name column_definition,): The Query is used to modify... name and add a index key on column of a table. Alter Table Name  | ADD
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
Runtime error
Runtime error  I have written 3n+1 code in java and it gives correct o/p but when i submit my code online for my contest it says runtime error.. how to know where is problem
Runtime Class
Runtime Class  How can we halt d execution withd help of exit(arg) method?? ...pls tag a code
runtime exception hibernate
runtime exception hibernate  runtime exception hibernate
SQL Alter Column
the table and add a column name that you want to add and its data type. ALTER TABLE table_name ADD column_name column-definition... SQL Alter Column      

Ads