------------------------------------------------------------------------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
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
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?
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??
SFR said:would it be possible for us to take a look at your code and debug?
import java.sql.*;
public class QueryTable
{
public static void main ( String[] args )
{
Connection con = null ;
try
{
String databaseURL = "jdbcracle:thin195.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() );
}
}
}
import java.sql.*;
public class CreateTable
{
public static void main ( String[] args )
{
Connection con = null ;
try
{
String databaseURL = "jdbcracle:thin195.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
}
}
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 ..
if(statement.execute([B]electQuery[/B])){
while ( resultSet.next() )
import java.sql.*;
public class QueryTable
{
public static void main ( String[] args )
{
Connection con = null ;
try
{
String databaseURL = "jdbcracle:thin195.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() );
}
}
}
One said:Sorry it was the wrong code
-----
try
{
String databaseURL = "jdbcracle:thin:@195.229.161.19:1521:sales" ;
String driverName = "oracle.jdbc.driver.OracleDriver" ;
String user = "" ;
String password = "" ;
[B]*/[/B]
resultSet.close() ;
}
statement.close();
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 ?