Suren Babu

Greenhorn
+ Follow
since Oct 23, 2000
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 Suren Babu

Thanks a lot Dave ...
Need some more clarifications regarding this...
1\ Moving setLong to setString works for all databases?. Our product supports Sybase, Oracle , MSSQL.
2\ Any idea how reliable is Sun's JDBC-ODBC Driver. Shall we go ahead with this for product based development.
3\ Do you know any URLs which has all the known issues / defects in Sun's JDBC-ODBC bridge.
Thanks
Database: MS SQL 2000
Platform: Windows 2000 sp2, Windows NT sp6a
Protocol to DB: TCPIP
JDBC-ODBC does not work for long datatypes using prepared statements. I use sample database pubs for this. I have a created table called base...
create table base
( id$ bigint, name varchar(80) )
where i inserted couple of rows with id$ containing values ranging from 2^8, 2^16, 2^31, 2^32, 2^63.
Executing the following code for id$ values less than 2^31 works fine. Exceeding that range didn't return me any rows even though i have rows in table.
Here is the code...
import java.sql.*;
import java.io.*;
public class TestJDBCODBC
{
Connection conn = null ;
long rowCnt = 0;
public TestJDBCODBC( String args[] ) throws Exception
{
rowCnt = Long.parseLong( args[0] ) ;

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection("jdbc dbc ubdb", "sa", "");
testSampleDB() ;
}
public static void main(String[] args) throws Exception
{
new TestJDBCODBC( args );
}

public void testSampleDB() throws Exception
{
System.out.println("testSampleDB");
s //String Query = "SELECT rowcnt FrOM sysindexes where rowcnt=?";
String Query = "SELECT id$, name FrOM base where id$=?";

PreparedStatement pstmt = conn.prepareStatement(Query);
//stmt.clearParameters();
pstmt.setLong( 1, rowCnt ) ;

ResultSet rset1 = pstmt.executeQuery();

if(rset1!=null)
{
//System.out.println("resultset is NOT null: " + rset1);
while(rset1.next())
{
System.out.print(rset1.getLong(1) +", ");
System.out.println(rset1.getString(2));
}
}

}
}
Hi, I tried the same code what you posted, but still i am getting the following error at runtime...
Exception in thread "main" java.lang.NoSuchMethodException
at java.lang.Class.getMethod0(Native Method)
at java.lang.Class.getMethod(Unknown Source)
at ReflectionTest.main(ReflectionTest.java:24)
Here is the code i tried...
A a = new A() ;
Class c = a.getClass() ;
Class[] longClass = new Class[1];
longClass[0] = long.class;
try
{
Method m = c.getMethod("longWithParam", longClass);
m.invoke(a, new Object[] {new Long(5L)});
}
catch (NoSuchMethodException e)
{
e.printStackTrace(); // prints this
}
catch (Exception e)
{
e.printStackTrace();
}
No Clue why this happening...
One interesting thing is...
instead of this line... longClass[0] = long.class ;
if i replace by this...
longClass[0] = Class.forName("java.lang.Long") ;
it works perfectly.
20 years ago
Small correction to your code. Instead of this line...
longClass[0] = long.class;
if you replace with
longClass[0] = Class.forName("java.lang.Long") ;
it works. I still don't know why it didn't work in previous case.
Any Idea?
Thanks
20 years ago
Thanks a lot cindy...
But still after changing to Object, i am getting 'argument type mismatch'. Could you help me on this...
Here is the code...
import java.lang.reflect.* ;
class ReflectionTest {
public static void main(String []args) throws Exception
{
A a = new A() ;
Class c = a.getClass() ;
/*
Method m = c.getMethod("longWithoutParam", null);
m.invoke(a, null);
*/
Class longClass[] = new Class [1];
longClass [0] = Class.forName("java.lang.Long") ;
//System.out.println( longClass[0].isPrimitive() );
Method m = c.getMethod("longWithParam", longClass);
m.invoke(a, (Object [])longClass); // Runtime error here

}
}
class A {
public void longWithParam( java.lang.Long l ) {
System.out.println("longWithParam method invoked") ;
}
public void longWithoutParam( ) {
System.out.println("longWithoutParam method invoked") ;
}
}

[This message has been edited by Suren Babu (edited June 05, 2001).]
20 years ago
I want to invoek a method which takes primitive as parameter through reflection..
import java.lang.reflect.* ;
class ReflectionTest {
public static void main(String []args) throws Exception
{
A a = new A() ;
Class c = a.getClass() ;
/*
Method m = c.getMethod("longWithoutParam", null);
m.invoke(a, null);
*/
Class longClass[] = new Class [1];
longClass [0] = Long.TYPE ;
System.out.println( longClass[0].isPrimitive() );
Method m = c.getMethod("longWithParam", longClass);
m.invoke(a, longClass);

}
}

class A {
public void longWithParam( long l ) {
System.out.println("longWithParam method invoked") ;
}
public void longWithoutParam( ) {
System.out.println("longWithoutParam method invoked") ;
}
}

After compilation and trying to run says 'argument type mismatch' can some body explain me what is happening...
20 years ago
Hi all,
>
> I want TreeSelectionEvent to be triggered (inturn to execute
> valueChanged()) without selecting the node manually (ie.. through
> KB / Mouse )
>
> How can I achieve this ?
>
> Thanks in advance,
> Suren
20 years ago
What is serialVersionUID field? Why it is required?. Where it is used? Is it required for all classes?
20 years ago
Here is the program...
I want the buttons to be laid of in this fashion..
Prev|Next Cancel Help.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class FlowLayoutTest extends JFrame {
JButton prev, next, cancel, help;

FlowLayoutTest() {
//create Bottom Panel
FlowLayout fLayout = new FlowLayout(FlowLayout.RIGHT, 0, 5);
System.out.println(fLayout.getHgap());
JPanel bottomPanel = new JPanel(fLayout);
prev = new JButton("PREVIOUS");
bottomPanel.add( prev );

next = new JButton("NEXT");
bottomPanel.add( next );

fLayout.setHgap(20);
cancel = new JButton("CANCEL");
bottomPanel.add( cancel );

fLayout.setHgap(5);
help = new JButton("HELP");
bottomPanel.add( help );
getContentPane().add( bottomPanel, BorderLayout.SOUTH );
setBounds(300, 300, 400, 400);
setVisible(true);
}

static void main(String []args) {
new FlowLayoutTest();
}
}
Running this program always has 5 pixel size of Horizontal gap irrespective of your settings.. can somebody explain me.. Is it a bug>
Suren
20 years ago
and also YES.. the duration is 120 mts..now. Exam software also tells that.
Threads are the tricky questions which i got only 75%. Here is the question distribution...
Threads: 8 questions
IO: 7 questions
Collection: 2
Accesss & Declaration: 5
etc
Also i noticed that difficult portions like threads, IO are occupying the initial questions. After noticing that i skipped the harder questions and attended all other questions and came back to harder questions.
Thanks
20 years ago
Does the options for Question 1 is elaborate ?.. in sense there are some options which does not tell whether it is local or instance declaration.
Is it guaranteed that when the GC runs it releases the memory allocated by an object.
One if the mock exam is saying yes...
Here is the question...
11. Which statements about garbage collection are true?
A) The garbage collector runs in low memory situations
B) You can run the garbage collector when ever you want.
C) When it runs, it releases the memory allocated by an object.
D) Garbage collector immediately runs when you set the references to null.
The answers given by the site is.. AC
Could somebody put more highlight on this..
Thanks
This question is from http://www.javacaps.com/sjpc_mockexam.html.
I checked A and B, but the answers are A,B,E.
As the question said it is 8-bit file and InputStreamReader takes care of converting bytes to character i checked A and B. But i doudt Answer E as it purely deals with Character IO. Could some one explain why Answer E is correct.
Here is the question...
55. You have an 8-bit file using the character set defined by ISO 8859-8. You are writing an application to display this file in a TextArea. The local encoding is already set to 8859-8. How can you write a chunk of code to read the first line from this file?
You have three variables accessible to you:
myfile is the name of the file you want to read
stream is an InputStream object associated with this file
s is a String object
Select all valid answers.
A)
InputStreamReader reader = new InputStreamReader(stream, "8859-8");
BufferedReader buffer = new BufferedReader(reader);
s = buffer.readLine();
B)
InputStreamReader reader = new InputStreamReader(stream);
BufferedReader buffer = new BufferedReader(reader);
s = buffer.readLine();
C)
InputStreamReader reader = new InputStreamReader(myfile, "8859-8");
BufferedReader buffer = new BufferedReader(reader);
s = buffer.readLine();
D)
InputStreamReader reader = new InputStreamReader(myfile);
BufferedReader buffer = new BufferedReader(reader);
s = buffer.readLine();
E)
FileReader reader = new FileReader(myfile);
BufferedReader buffer = new BufferedReader(reader);
s = buffer.readLine();
Thanks in advance
can somebody tell me the answer for this..
Which of the following classes should have a finalize method?
A. A class that creates a socket
B. All classes
C. Any class that extends a class having a finalize method
D. Any class that creates an array of primitive values.
I guessed A but the answer is A and C.
i Don;t accept answer c becos.. if this is the case as all classes are child of class Object then all classes should have finalize() method right. In that case answer B is also correct.
Could somebody clear me on this...
Thanks
I feel the answers are run(), wait(), yield()
addon to the discussions above related to wait() and yield()
i think run() also - which CANNOT start the thread is the answer.
With the given thread in context, which is started using start() we cannot start() the same thread through run() method.. even though we can create child threads.
Any thoughts