SQL *plus command >>>> NEED HELP :)

One

New Member
Hi all,

I am not sure if this is the right place to put my question.

I wanna to know how can I embedded/execute SQL *Plus command in java code since it is not same to SQL command ? e.g. i want to execute the (DESC
command).

I appreciate any help.

Regards,



One
 

dragon2309

P.I Dragon
can you be more specific, what are you trying to do in java that would need an SQL call, yeh, so be more specific, what are you actually trying to achieve. us eggheads, we love intricate details, even if its not related....

dragon
 

One

New Member
dragon2309 said:
can you be more specific, what are you trying to do in java that would need an SQL call, yeh, so be more specific, what are you actually trying to achieve. us eggheads, we love intricate details, even if its not related....

dragon
------------------------------------------------------------------------
Ok I will try to be more specific and give you more detailes .. be ready for a longe story :D

First ( small part of my project idea)
I want to evaluate the memory usage of PLSQL code, just for now I am working with (SELECT statement).

Second(embedded SQL statement in java)
As you know we are using JDBC to do this step, I achived this part, and I can execute query from java using java.sql library.

last step (HERE is the problem)
I want to execute the Describe(DESC) command from SQL *plus to get info about the tables in the databace. The question is how I can execute this comman from a java code?

I hope my question is clear now :rolleyes:

ONE
 

One

New Member
Helloooooooooooo :(

14 views except me of course, and no one said hello ONE I don't have any answer :(


Anyway, thanks for those guys who crossed my subject


ONE :rolleyes:
 

dragon2309

P.I Dragon
sorry one, my lack of knowledge in java is kinda limiting this thread. try speaking to cromewell and mgoldb2, they seem to be technically minded like that....

dragon
 

One

New Member
dragon2309 said:
sorry one, my lack of knowledge in java is kinda limiting this thread. try speaking to cromewell and mgoldb2, they seem to be technically minded like that....

dragon

Thank you soooooooooooooo much dragon.. I appreciate your time

I don't know if I have to send them my question... ummm actually I will wait maybe they will see my question here :)

Thank you again bro :)
 

Cromewell

Administrator
Staff member
Hello One. There someone said it :)

Have you tried running the DESC command with the executeQuery method? If so what error/result did you get?
 

One

New Member
Cromewell said:
Hello One. There someone said it :)

Have you tried running the DESC command with the executeQuery method? If so what error/result did you get?


Hi Cromewell,

Thanks for replying me :)

Yes, I tried many time

Actually, I can't give you exact error message since I can't run the code from my home, only when I am working in the collage

As I remember, It was somthing like [invalid statement]

I debugged the code and see where is the mistake, it gave me error with executeQuery method. what I have did later is, I read the description of JDBC and see if there is any method support SQL *plus command, i didn't find anything :( !!!!

Any suggestions??
 

SFR

Truth fears no questions
One said:
Hi Cromewell,

Thanks for replying me :)

Yes, I tried many time

Actually, I can't give you exact error message since I can't run the code from my home, only when I am working in the collage

As I remember, It was somthing like [invalid statement]

I debugged the code and see where is the mistake, it gave me error with executeQuery method. what I have did later is, I read the description of JDBC and see if there is any method support SQL *plus command, i didn't find anything :( !!!!

Any suggestions??

would it be possible for us to take a look at your code and debug?
 

One

New Member
SFR said:
would it be possible for us to take a look at your code and debug?

It is very simple one, first I tried to just execute SQL statement (select), then my instructore asked me to do it with (DESC command)

I think nothing new in this code, since it is just connect, execute and get the result ..

This is the QueryTable class ..

import java.sql.*;

public class QueryTable
{

public static void main ( String[] args )
{
Connection con = null ;

try
{




String databaseURL = "jdbc:eek:racle:thin:mad:195.229.161.19:1521:sales" ;
String driverName = "oracle.jdbc.driver.OracleDriver" ;
String user = "" ;
String password = "" ;


Class.forName ( driverName ).newInstance();

con = DriverManager.getConnection ( databaseURL , user , password );

if ( ! con.isClosed() )
System.out.println ( "Successfully connected to the DataBase Server..." );

Statement statement ;

statement = con.createStatement();

//--------------------------------------------------------------------------------------------

String selectQuery = "SELECT * from STUDENTS" ;

ResultSet resultSet = null ;



if(statement.execute(electQuery)){
while ( resultSet.next() )
{
String student_id = ( String ) resultSet.getObject("student_id");
String first_Name = ( String ) resultSet.getObject("first_Name") ;
String last_Name = ( String ) resultSet.getObject ( "last_Name" ) ;
String city = ( String ) resultSet.getObject ( "city" ) ;

System.out.println ( "-----------------------------------" );
System.out.println ( "student_Id = " + student_id);
System.out.println ( "first_Name = " + first_Name );
System.out.println ( "last_Name = " + last_Name );
System.out.println ( "city = " + city );



}//while
resultSet.close() ;
}//if




statement.close();

if ( con != null )
con.close();

}
catch ( Exception e )
{
System.err.println ( "Exception: " + e.getMessage() );
}

}

}
 

One

New Member
Here is the CreateTable class.. you may want to use it :)

----
import java.sql.*;

public class CreateTable
{

public static void main ( String[] args )
{
Connection con = null ;

try
{


String databaseURL = "jdbc:eek:racle:thin:mad:195.229.161.19:1521:sales" ;
String driverName = "oracle.jdbc.driver.OracleDriver" ;
String user = "" ;
String password = "" ;




Class.forName ( driverName ).newInstance();

con = DriverManager.getConnection ( databaseURL , user , password );

if ( ! con.isClosed() )
System.out.println ( "Successfully connected to the DataBase Server..." );


Statement statement ;

statement = con.createStatement();

String createQuery = "CREATE TABLE STUDENTS ( " +

"student_Id VARCHAR ( 16 ) NOT NULL , " +
"first_Name VARCHAR ( 16 ) NOT NULL , " +
"last_Name VARCHAR ( 16 ) NOT NULL , " +
"city VARCHAR ( 64 ) NOT NULL , " +

"PRIMARY KEY ( student_Id ) " +

" )";


int returnValue ;


returnValue = statement.executeUpdate ( createQuery );
System.out.println ( "Table STUDENT has been created Successfully." );



statement.close();

if ( con != null )
con.close();

}
catch ( Exception e )
{
System.err.println ( "Exception: " + e.getMessage() );
}//catch

}

}
 

SFR

Truth fears no questions
One said:
It is very simple one, first I tried to just execute SQL statement (select), then my instructore asked me to do it with (DESC command)

I think nothing new in this code, since it is just connect, execute and get the result ..

This is the QueryTable class ..

at a quick glance I noticed:

Code:
if(statement.execute([B]electQuery[/B])){
while ( resultSet.next() )
 

One

New Member
Sorry it was the wrong code :(

-----

import java.sql.*;

public class QueryTable
{

public static void main ( String[] args )
{
Connection con = null ;

try
{

String databaseURL = "jdbcracle:thin:mad:195.229.161.19:1521:sales" ;
String driverName = "oracle.jdbc.driver.OracleDriver" ;
String user = "" ;
String password = "" ;
*/


Class.forName ( driverName ).newInstance();

con = DriverManager.getConnection ( databaseURL , user , password );

if ( ! con.isClosed() )
System.out.println ( "Successfully connected to the DataBase Server..." );

Statement statement ;

statement = con.createStatement();

String selectQuery = "SELECT * FROM STUDENT" ;

ResultSet resultSet = null ;

resultSet = statement.executeQuery ( selectQuery );


if ( resultSet != null ) // Succes


while ( resultSet.next() )
{

String studentId = ( String ) resultSet.getObject ( "studentId" ) ;
String firstName = ( String ) resultSet.getObject ( "firstName" ) ;
String lastName = ( String ) resultSet.getObject ( "lastName" ) ;
String city = ( String ) resultSet.getObject ( "city" ) ;

System.out.println ( "-----------------------------------" );
System.out.println ( "studentId = " + studentId );
System.out.println ( "firstName = " + firstName );
System.out.println ( "lastName = " + lastName );
System.out.println ( "city = " + city );
}

resultSet.close() ;

}

statement.close();

if ( con != null )
con.close();

}
catch ( Exception e )
{
System.err.println ( "Exception: " + e.getMessage() );
}

}

}
 

SFR

Truth fears no questions
One said:
Sorry it was the wrong code :(

-----


Code:
try
{
String databaseURL = "jdbcracle:thin:@195.229.161.19:1521:sales" ;
String driverName = "oracle.jdbc.driver.OracleDriver" ;
String user = "" ;
String password = "" ;
[B]*/[/B]

delete */

right after the try block you need the catch block, the brackets are incorrect. delete the } in the following code

Code:
resultSet.close() ;
}
statement.close();
 

One

New Member
*/ << this is was mistake too ..

} << ok I will

put do you think it will execute DESC command ???

This code is work fine with me, when I am trying to execute DESC it gave me (invalid statement)

What do you think ?
 

SFR

Truth fears no questions
One said:
*/ << this is was mistake too ..

} << ok I will

put do you think it will execute DESC command ???

This code is work fine with me, when I am trying to execute DESC it gave me (invalid statement)

What do you think ?



If you want to order the records by descending you need to change the SQL statement.

SELECT * FROM STUDENT order by {field in table you want to order by} DESC


if you want to view a description of a table in oracle you enter: desc table_name
 
Last edited:

One

New Member
SFR ..

I didn't get your point.

I want to get the info that supply by DESC command( fields name and datatype)
 

One

New Member
Hey guys, I got an answer some where else .. what do you think about it ?? any suggestion??

----------
SQL*Plus is a command-line application. That's it. There is no fancy interface
to access its functionality, you have to start it up and capture the output.

Possibly iSQL*Plus would be easier to access from Java since it's web-based,
though this is a complete guess since I don't know Java.

This all sounds like rather a lot of work for something that will be very
inefficient, though.
 
Top