Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!

satish sathineni

Ranch Hand
+ Follow
since May 03, 2004
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by satish sathineni

Hi,

DDLExample.java
// -----------------------------------------------------------------------------

import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;


/**
* -----------------------------------------------------------------------------
* The following class provides an example of using JDBC to perform DDL
* statements in an Oracle database.
* -----------------------------------------------------------------------------
*/

public class DDLExample {

final static String driverClass = "oracle.jdbc.driver.OracleDriver";
final static String connectionURL = "jdbc racle:thin:@localhost:1521:CUSTDB";
final static String userID = "system";
final static String userPassword = "manager";
Connection con = null;


/**
* Construct a DDLExample object. This constructor will create an Oracle
* database connection.
*/
public DDLExample() {

try {

System.out.print(" Loading JDBC Driver -> " + driverClass + "\n");
Class.forName(driverClass).newInstance();

System.out.print(" Connecting to -> " + connectionURL + "\n");
this.con = DriverManager.getConnection(connectionURL, userID, userPassword);
System.out.print(" Connected as -> " + userID + "\n");

} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}

}


/**
* Method used to create a table, insert rows into it, query all records,
* delete all records and finally drop the example table.
*/
public void performDDL() {

Statement stmt = null;
ResultSet rset = null;
int insertResults;
int deleteResults;

try {

System.out.print(" Creating Statement...\n");
stmt = con.createStatement ();


/*
* -----------------------------------------------------------------
* CREATE TABLE
* -----------------------------------------------------------------
*/
System.out.print("\n");
System.out.print("+-------------------------------+\n");
System.out.print("| CREATE TABLE |\n");
System.out.print("+-------------------------------+\n");
System.out.print("\n");

System.out.print("Creating Table [TEST_JDBC]\n");

stmt.executeUpdate("CREATE TABLE test_jdbc (" +
" test_jdbc_intr_no NUMBER(15) " +
" , test_jdbc_name VARCHAR2(100) " +
" , test_jdbc_null_value VARCHAR2(100))");
System.out.print("Table Created...\n");


/*
* -----------------------------------------------------------------
* INSERT INTO TABLE
* -----------------------------------------------------------------
*/
System.out.print("\n");
System.out.print("+-------------------------------+\n");
System.out.print("| INSERT VALUES |\n");
System.out.print("+-------------------------------+\n");
System.out.print("\n");

insertResults = stmt.executeUpdate("INSERT INTO test_jdbc VALUES(" +
" 100" +
" , 'James Smith'" +
" , null)");
System.out.print(" RESULTS -> " + insertResults + " row created.\n");
insertResults = stmt.executeUpdate("INSERT INTO test_jdbc VALUES(" +
" 200" +
" , 'Amy Miller'" +
" , null)");
System.out.print(" RESULTS -> " + insertResults + " row created.\n");
insertResults = stmt.executeUpdate("INSERT INTO test_jdbc VALUES(" +
" 300" +
" , 'Andy Phillips'" +
" , null)");
System.out.print(" RESULTS -> " + insertResults + " row created.\n");
insertResults = stmt.executeUpdate("INSERT INTO test_jdbc VALUES(" +
" 400" +
" , 'Jimmy Black'" +
" , null)");
System.out.print(" RESULTS -> " + insertResults + " row created.\n");
insertResults = stmt.executeUpdate("INSERT INTO test_jdbc VALUES(" +
" 500" +
" , 'Jane Dee'" +
" , null)");
System.out.print(" RESULTS -> " + insertResults + " row created.\n");


/*
* -----------------------------------------------------------------
* COMMIT TRANSACTION
* -----------------------------------------------------------------
*/
System.out.print("Commiting Transaction...\n");
con.commit();


/*
* -----------------------------------------------------------------
* EXECUTE QUERY
* -----------------------------------------------------------------
*/
System.out.print("\n");
System.out.print("+-------------------------------+\n");
System.out.print("| EXECUTE QUERY (Forward) |\n");
System.out.print("+-------------------------------+\n");
System.out.print("\n");

System.out.print("Opening ResultsSet...\n");
rset = stmt.executeQuery ("SELECT * FROM test_jdbc ORDER BY test_jdbc_intr_no");

while (rset.next ()) {

int rowNumber;
int test_jdbc_intr_no;
String test_jdbc_name;
String test_jdbc_null_value;

rowNumber = rset.getRow();

test_jdbc_intr_no = rset.getInt(1);
if ( rset.wasNull() ) {
test_jdbc_intr_no = -1;
}

test_jdbc_name = rset.getString(2);
if ( rset.wasNull() ) {
test_jdbc_name = "<null>";
}

test_jdbc_null_value = rset.getString(3);
if ( rset.wasNull() ) {
test_jdbc_null_value = "<null>";
}

System.out.print(
" RESULTS -> [R" + rowNumber + "] " +
test_jdbc_intr_no + " - " + test_jdbc_name +
" - " + test_jdbc_null_value + "\n");
}


/*
* -----------------------------------------------------------------
* DELETE ALL RECORDS FROM TABLE
* -----------------------------------------------------------------
*/

System.out.print("\n");
System.out.print("+-------------------------------+\n");
System.out.print("| DELETE ALL RECORDS FROM TABLE |\n");
System.out.print("+-------------------------------+\n");
System.out.print("\n");

deleteResults = stmt.executeUpdate("DELETE FROM test_jdbc");
System.out.print(" RESULTS -> " + deleteResults + " rows deleted.\n");


/*
* -----------------------------------------------------------------
* COMMIT TRANSACTION
* -----------------------------------------------------------------
*/
System.out.print("Commiting Transaction...\n");
con.commit();


/*
* -----------------------------------------------------------------
* DROP TABLE
* -----------------------------------------------------------------
*/
System.out.print("\n");
System.out.print("+-------------------------------+\n");
System.out.print("| DROP TABLE |\n");
System.out.print("+-------------------------------+\n");
System.out.print("\n");

System.out.print("Dropping Table\n");
stmt.executeUpdate("DROP TABLE test_jdbc");


/*
* -----------------------------------------------------------------
* CLOSE RESULTSET AND STATEMENT OBJECTS
* -----------------------------------------------------------------
*/
System.out.println();
System.out.print(" Closing ResultSet...\n");
rset.close();

System.out.print(" Closing Statement...\n");
stmt.close();

} catch (SQLException e) {

e.printStackTrace();

}

}


/**
* Close down Oracle connection.
*/
public void closeConnection() {

try {
System.out.print(" Closing Connection...\n");
con.close();

} catch (SQLException e) {

e.printStackTrace();

}

}


/**
* Sole entry point to the class and application.
* @param args Array of String arguments.
* @exception java.lang.InterruptedException
* Thrown from the Thread class.
*/
public static void main(String[] args)
throws java.lang.InterruptedException {

DDLExample ddlExample = new DDLExample();
ddlExample.performDDL();
ddlExample.closeConnection();

}

}





satish
I think the best practice would be to use "Singleton Pattern" design for your GUI class...

That is "Singleton Pattern" allows only one Instance for a particular class...

a.)
This is achieved by making the Constructor of the respective class as private method
There by no one can intialize the object in a routine way becoz the visibility of the
constructor is private..

b.)
To create the instance of that singleton class is done by providing a Static method which
returns the object of the class.
The logic for providing only single instance should go here in the Static method...

I can provide more info providing more details about the context and what is ur exact requirement.



Satish
15 years ago
Hi Sridevi!!

I think u have done most of the work ...

u do following things ::

a. Run the RmiServer example program in one terminal window(Linux)/ (Solaris )
java <name of the server program>

b. Run the Rmiclient example program in one terminal window(Linux)/ (Solaris )
java <name of the server program>

I think this should show u r first Hello world RMI example...

regards
satish
15 years ago
As far my knowledge goes Oracle 9i could have come with some sort of web application server with it becoz later oracle released Oracle 9i App Server

could u clarify the doubt that ur using Oracle 9i database or some enterprise edition...

Satish......
15 years ago
Hi,

U can Increase the JAVA_OPTS value in the Catalina.sh for linux box
Catalina.bat for win box

Open the respective file in the respective text editors

Modify JAVA_OPTS variable value

for Linux Box
export JAVA_OPTS = Xmx256m /// for 256 MB or what ever ur requirement is

for Windows Box
set JAVA_OPTS = Xmx256m


Satish Kumar
15 years ago
Hi,

It is really good question...

.toString() is defined the Object class all other objects mostly extend from the
Object class they overridden the .toString()

This is done becoz to represent the meaningful representation of the class behaviour or stuff like that ....

Now one important fact i came to know about String class and its .toString() is that it returns the value assigned to the String

So when u r aware that the Return Type is String u can call either

.toString() or (String) both gives u the same output the
value of the String

for other than String objects u cannot expect the output of the .toString() method


Regards
Satish
15 years ago
if u want take adtvantage of the eclipse built in java compiling facilities and other like adding new packages and other compiling only with respect to java....

other wise u dont get all the java specific tools for the java project ......
As far as Brand name and the Company Status i would prefer HP

And other things like the Hikes and other facilities

Also important to mention the Work Culture and Environment i dont have clear IDea...

The above things if one could answer u can join without any second thought
15 years ago
Try using conditional logic to display the different tables ......
15 years ago
JSP
The Following code the reasons for "Page Cannot Be Displayed"

1. The server is not properly not started check the startup.bat for windows startup.sh for linux
2. Check the Server.xml file for the port number if it is set to 8080 ...
3.Only for windows check that IIS server is running as system process or not if it is running as systems startsup then change the Tomcat Port to some other number basically 8080 port is default for the IIS web server on windows OS.

For further clarifications do write u r OS version Tomcat version


Regards
S.N.Satish Kumar
15 years ago
Servlets are used to develop dynamic webcontent ie WebApplications

Servlets are normal java classes Who generally have to extend
javax.servlet.http.HttpServlet class.

These are precompiled classes. (This is nothing but a Servlet Template)
Instead in a JSP java code is embedded in HTML for easier Page generation
as HTML code generation in Servlets could be very tedious if the HTML
data is large.
At Runtime the JSP/Servlet container converts the JSP into a Servlet and
executes it.


Regards
Satish
15 years ago
Servlets are used to develop dynamic webcontent ie WebApplications

Servlets are normal java classes Who generally have to extend
javax.servlet.http.HttpServlet class.

These are precompiled classes. (This is nothing but a Servlet Template)
Instead in a JSP java code is embedded in HTML for easier Page generation
as HTML code generation in Servlets could be very tedious if the HTML
data is large.
At Runtime the JSP/Servlet container converts the JSP into a Servlet and
executes it.


Regards
Satish
15 years ago
JSP
Hi,

Object type Comparision

String -->> immutable (Value once assigned cannot be modified)
StringBuffer -->> mutable (Value can be modified).

Performance comparision

Performance wise StringBuffer is better when u compare String with StringBuffer in string manipulation that is
ex:
String str = "Hello";
str = str+"World" ;
sop(str);

StringBuffer sbstr = new StringBuffer("Hello");
sbstr.append("world");
sop(sbstr.toString());

if we look at the above example the major and hidden difference is internally how JVM handles the string manipulation....

when we say str = str+"World";

internally ::

StringBuffer xxx = new StringBuffer(str);
xxx.append("World");
str = xxx.toString();

Now u can make out that internally there is a overhead of converting the String str to StringBuffer and applying append method on that and finally it is assigned backto the str the modifed str....


Cheers
satish
15 years ago
Hi,

Manish

I also faced the same solution for longtime i was able to solve it..

first i would like to know the OS ur running the tomcat and version of tomcat webserver....

regards
satish kumar
As Julian Said use a hidden variable with some "xxx" name and assign different values depending on the page submit to a servlet

request.getParameter("xxx");

and then depending on the value u forwarding to different pages.....


regards
satish
15 years ago