Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Java program to compare performance

Using any source of data, develop a program which can compare the performance of any two of the following techniques:
(i) JDBC direct connection to database
(ii) Direct socket connection - data held in memory
(iii) CORBA connection

NB comparison could be througput in seconds

Please help me get this program
[340 byte] By [yaosman_1] at [2007-11-11 9:57:05]
# 1 Re: Java program to compare performance
So, what is your plan? What have you implemented?
nspils at 2007-11-11 22:32:14 >
# 2 Re: Java program to compare performance
import java.sql.*;
public class Test

{
public static void main(String[] args)

{

try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// set this to a MS Access DB you have on your machine
String filename = "p:/java/mdbTEST.mdb";
String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";
database+= filename.trim() + ";DriverID=22;READONLY=true}"; // add on to the end
// now we can get the connection from the DriverManager
Connection con = DriverManager.getConnection( database ,"","");
Statement s = con.createStatement();
s.execute("create table TEST12345 ( column_name integer )"); // create a table
s.execute("insert into TEST12345 values(1)"); // insert some data into the table
s.execute("select column_name from TEST12345"); // select the data from the table
ResultSet rs = s.getResultSet(); // get any ResultSet that came from our query
if (rs != null) // if rs == null, then there is no ResultSet to view
while ( rs.next() ) // this will step through our data row-by-row

{
/* the next line will get the first column in our current row's ResultSet
as a String ( getString( columnNumber) ) and output it to the screen */
System.out.println("Data from column_name: " + rs.getString(1) );
}

s.execute("drop table TEST12345");
s.close(); // close the Statement to let the database know we're done with it
con.close(); // close the Connection to let the database know we're done with it
}

catch (Exception err) {
System.out.println("ERROR: " + err);
}

}

}
//save this code into a file called Test.java and compile it

I have this program for JDBC connection to an access database, I will like to know how many seconds it takes to connect to the database, I also want another connection this time using rmi and how many seconds it also takes to connect so that I can compare which of them is faster
yaosman_1 at 2007-11-11 22:33:08 >
# 3 Re: Java program to compare performance
That looks like a good start. Remember you are going to need to start and stop a timer, too. It would be a good idea to have an interface whose functions you call, then put various implementing classes in its place which implement those functions - that way your testing structure is the same and the only thing that changes is the implementation - this is a use of the "Strategy" pattern.

Now, how do you connect using RMI, to do the same thing that the JDBC connection does?
nspils at 2007-11-11 22:34:18 >