Forum Stats

  • 3,722,440 Users
  • 2,244,312 Discussions
  • 7,849,837 Comments

Discussions

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

java.sql.SQLSyntaxErrorException: ORA-00903: invalid table name

Bitra Hemanth
Bitra Hemanth Member Posts: 69
edited December 2018 in Java Servlet

I am using below jsp script to apply select query from Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

JSP Program:

<%@ page import="java.sql.*" %>

<%

   String table=request.getParameter("TAB");

   try

   { Class.forName("oracle.jdbc.driver.OracleDriver");

     Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","SYSTEM","Hemanth22");

     Statement st=con.createStatement();

    

           if(st.execute("SELECT * from "+table))

              {  ResultSet rs=st.getResultSet();

                 ResultSetMetaData rsmd=rs.getMetaData();

                 int nc=rsmd.getColumnCount();

                    out.print("<body bgcolor=yellow text=blue>");

                         out.print("<table align=center>");

                   while(rs.next())

                      { out.print("<tr>");

                         for(int c=1;c<=nc;c++)

                           { out.print("<td>"+rs.getString(c)+"</td>");}

                         out.print("</tr>");

                       }

   

TNSNames Settings.

$cat tnsnames.ora

# tnsnames.ora Network Configuration File: /home/bhemanth/app/bhemanth/product/12.2.0/dbhome_1/network/admin/tnsnames.ora

# Generated by Oracle configuration tools.

LISTENER_ORCL =

  (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))

ORCL =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = orcl)

    )

  )

LISTENER_PDBORCL =

  (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))

PDBORCL =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = pdborcl)

    )

  )

JDK Version:

$java -version

java version "9.0.4"

Java(TM) SE Runtime Environment (build 9.0.4+11)

Java HotSpot(TM) 64-Bit Server VM (build 9.0.4+11, mixed mode)

$javac -version

javac 9.0.4

[[email protected] admin]$ tomcat version

Server version: Apache Tomcat/7.0.76

Server built:   Oct 16 2018 09:15:49 UTC

Server number:  7.0.76.0

OS Name:        Linux

OS Version:     3.10.0-862.3.2.el7.x86_64

Architecture:   amd64

JVM Version:    9.0.4+11

JVM Vendor:     Oracle Corporation

OS i am using in CentOS7.5

Can you please advice why it is showing invalid table name even i am having some data in tab i.e. it give list of tables

Best Answer

Answers

Sign In or Register to comment.