| Back to Questions Page |
| |
| Question |
How can we get the details for printing the employee
details at run time using JDBC connectivity? can u provide
the coding for that? Its urgent? |
Rank |
Answer Posted By |
|
Question Submitted By :: Hema |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | Here is d coding for JDBC Connectivity to retrieve employee
details
I hv provided comments also so u can understand it better
--------------------*-----------------------------
/**
*
* @author KIRAN
*/
import java.sql.*;
import java.io.*;
public class JDBCConnection
{
public static void main(String args[])
{
Connection conn;
Statement stmt;
ResultSet rs;
try
{
//loads JDBC driver
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(Exception e)
{
e.printStackTrace();
}
try
{
//set connection string
conn=DriverManager.getConnection("jdbc:odbc:employeedsn");//here
loads dsn named empdsn
//creates statement
stmt=conn.createStatement();
//to get records from database using
resultset
rs=stmt.executeQuery("select * from emp");//for dis 1st
create emp named table
System.out.println("EId
Ename DOB Dept
Salary\n");
while(rs.next())//moves cursor to the next record until
it reaches d last record
{
System.out.println(+rs.getInt(1)+"
"+rs.getString(2)+" "+rs.getString(3)+"
"+rs.getString(4)+" "+rs.getInt(5));
}
stmt.close();
conn.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
Note:
-create emp table 1st wid attributes eid,ename,dob,dept,n
salary
-to add dsn(data source name)go to control
panel->Administrative Tools->Data Sources (ODBC) then one
small window will get opend..
-click on System DSN tab->Add->n select "Microsoft Access
Drive(*.mdb)"->finish->type Data Source Name(as i hv typed
in program "employeedsn" if u dnt want to change that dsn
which is written in d line
conn=DriverManager.getConnection("jdbc:odbc:employeedsn")
-you can give ne name tht u want instead of employeedsn...u
only need to provide d same name in Data Source Name
-next is no need to provide nethng for description
-then click on->select(to select database in *.mdb form)
---to select database table select drive on which u hv
saved ur database table n select that table by going to d
folder where u hv stored it by going to an appropriate directory
----if u select correct directory,table name will b
displyed in left hand side list box which then u need to
select n click on "OK" n again click on "OK"
----Your DSN will be displyed in System Data Sources List
---click on Ok n once you done this run the program  |
| Kiran Kamble |
| |
| |
| Question |
Can you forward data from a servlet to a regular .java
class that is not a servlet? |
Rank |
Answer Posted By |
|
Question Submitted By :: Ash |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | put it in a session as an attribute.  |
| Tej |
| |
| |
| Answer | I think it is not possible.  |
| Hfgf |
| |
| |
|
|
| |
| Question |
how to store and retrive a set of values without using an
array |
Rank |
Answer Posted By |
|
Question Submitted By :: Kiran |
| This Interview Question Asked @ Maximus , Hcl |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | please post the answer...
thanks and regards
kiran.y  |
| Kiran |
| |
| |
| Answer | link list i think..  |
| Karthik |
| |
| |
| Answer | I think U need this .......
/*****************************************************/
import java.util.*;
class TreeSetDemo {
public static void main(String args[]) {
// Create a tree set.
TreeSet<String> ts = new TreeSet<String>();
// Add elements to the tree set.
ts.add("C");
ts.add("A");
ts.add("B");
ts.add("E");
ts.add("F");
ts.add("D");
System.out.println(ts);
}
}
/******************************************************/
The output from this program is shown here:
[A, B, C, D, E, F]
/*******************************************************/
/********************************
************ AND ************
**********************************/
import java.util.*;
class HashSetDemo {
public static void main(String args[]) {
// Create a hash set.
HashSet<String> hs = new HashSet<String>();
// Add elements to the hash set.
hs.add("B");
hs.add("A");
hs.add("D");
hs.add("E");
hs.add("C");
hs.add("F");
System.out.println(hs);
}
}
/**************************************/
The following is the output from this program:
[D, A, F, C, B, E]
/****************************************/  |
| Shiva |
| |
| |
| Answer | using
BufferedReadered br=new BufferedReader(new InputStreamReader
(System.in));
while (br.readline)
System.out.println(br);
B  |
| Ashok Kumar |
| |
| |
| Question |
inner join,outerjoin,trigger,stored procedure explain with
code snippets? |
Rank |
Answer Posted By |
|
Question Submitted By :: Aravinthraj |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | Join:It is the combining of two rows from different tables
based on the comparative values in selected columns.
Types of Join : Cross Join, Inner Join or equi join and
Outer Join which comprises of Left join and Right join.
Inner Join : It is used to select certain fields from both
tables and only correct rows will be joined together.
Sytax:SELECT <column_name> FROM <Table1>, <Table2> WHERE
(Table1.column = Table2.column)
Outer Join:
Left join: It returns all the data's from the table
present in left of the join and only those data's from the
right tabel which matches the condition.
Syntax:SELECT <column_name> FROM <Table1> LEFT JOIN
<Table2> ON Table1.column = Table2.column (Conditions like
WHERE and USING)
Right join: It returns all the data's from the table
present in right of the join and only those data's from the
left tabel which matches the condition.
Syntax:SELECT <column_name> FROM <Table1> LEFT JOIN
<Table2> ON Table1.column = Table2.column (Conditions like
WHERE and USING)  |
| Vj |
| |
| |
| Question |
How to convert string containing decimal point into integer
in java? For example given a string like "3.14" as input how
to get integer 3 as result. |
Rank |
Answer Posted By |
|
Question Submitted By :: Pradeep |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | /* How to convert string containing decimal point into integer
in java? For example given a string like "3.14" as input how
to get integer 3 as result. */
String myStr = "3.14";
Int myInt = Float.valueOf(myStr).intvalue();  |
| Pradeep |
| |
| |
| Answer | class StringToInt {
public static void main (String[] args) {
String s="3.14";
double i=Double.parseDouble(s);
int i1=(int)i;
System.out.println (i1);
}
}  |
| Indresh_ips |
| |
| |
| Answer | I don't know  |
| Subramanyam |
| |
| |
| Answer | /***************************************************/
import java.io.*;
class StringToInt
{
public static void main(String a[]) throws
IOException
{
String s;
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
do{
s=br.readLine();
System.out.println("U R Sting
is: "+s);
}while(s.equals(" "));
try
{
double d = new Double(s);
int j = (int)d;
System.out.println(j);
}catch(NumberFormatException e)
{
System.out.println(" Your String is
Not a Number:.. ");
}
}
}  |
| Shiva Kumar |
| |
| |
| Answer | For the above given question 3 is answer while converting
decimal to integer  |
| Rajasekaran.p |
| |
| |
| Answer | String str = "5.22";
Int result = Float.valueOf(mystr).intValue();
// value of result is 5  |
| Troya |
| |
| |
| Question |
how to display date after one month using from today date
in jsp |
Rank |
Answer Posted By |
|
Question Submitted By :: Guest |
| This Interview Question Asked @ TCS |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | You have to use javscript or use some database connectivity
in JSP program.  |
| Sandeep_1985 |
| |
| |
| Answer | We should use Date object from java or JavaScript.  |
| Balu |
| |
| |
| Answer | Calendar c=Calendar.getInstance();
c.roll(Calendar.MONTH, 1);
Date d4 = c.getTime();
System.out.println("new date " + d4.toString() );  |
| Aravind & Guhan |
| |
| |
| Question |
How to create and run runnable jar file of a Java Project. |
Rank |
Answer Posted By |
|
Question Submitted By :: Mkumar_028 |
| This Interview Question Asked @ HCL , Sathyam, Wipro, Usa, Tcs, All Places |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | Common Examples
----------------
Let's say I have a Java application consisting of three
source files that I wish to distribute:
One.javaTwo.javaThree.java
I also want to call my JAR file example.jar. To make a JAR
file with just One.java:
jar CF example.jar One.java
To make a file with all three files listed separately:
jar CF example.jar One.java Two.java Three.java
To make a file with all three files using a pattern match:
jar CF example.jar *.java
It goes (almost) without saying that the source files are
in the same directory you are running the jar command in.
------------------------------------------------------------
-----------------
Compress Files To An Executable Java Archive (JAR)
---------------------------------------------------
It is also possible to make an archive that can be executed
(run) by Java and even by a double click through your OS,
if you have it set up correctly. Of course, to do this you
must store compiled class files in the archive, as well as
or instead of Java source files, since Java source files
cannot be run!
Continuing the example above, I now compile my Java source
files:
javac *Java
or
javac One.java Two.java Three.java
------------------------------------------------------------
--------------------
Create An Executable JAR
---------------------------
All JAR files contain something called a manifest file
which holds information Java wants to know. One piece of
information a manifest file may contain is the name of a
class that will be run if the JAR file is executed.
The first thing you must do is create a text file that
lists the "main" class - the class that has the main method
you want executed when the JAR is executed. Let's say that
Three from the above example has the main method I want
executed. I create a text file called "mainClass.txt" with
the following text:
Main-Class: Three
IMPORTANT: the text file only needs the one line of text
for this purpose. However, the file must end with a blank
line or this will not work, ie the file has two lines in
it - the second one is empty. Note too the class is
called "Three" and not "Three.java" (the file containing
the source code) or "Three.class" (the file containing the
byte codes). If your class file is in a package hierarchy,
you must use the fully qualified name of the class
(eg "myPackage.MyClass").
I then run the jar utility with this command line:
jar cmf mainClass.txt example.jar *.class
With this line, I told jar to create a JAR file (option c)
with modifications to the manifest file (option m) as
specified within mainClass.txt, naming the JAR file (option
f) as example.jar and including everything that matches the
pattern *Class
------------------------------------------------------------
--------------------
Running An Executable JAR From Command Line
---------------------------------------------
I can run it from the command line like this:
java -jar example.jar
------------------------------------------------------------
--------------------
Running An Executable JAR From Explorer (Windows)
-------------------------------------------------
Within Windows, it is also possible to set up Windows
Explorer so that you can double click on the JAR file icon
to execute the file (handy for GUI applications). The first
thing you must do is set up the correct association with
the 'javaw.exe' application that JDK for Windows will have.
Click here for an older example with pictures! Open Windows
Explorer and select Tools | Folder Options | File Types.
If there is no JAR file type, create it. Give it a
description like
jar - Executable Jar File
to ensure it sorts under 'jar'. Create or edit the action
called "open" and associate it with the following action:
"C:\Java\jdk1.4.0\bin\javaw.exe" -jar "%1"
Of course, you will replace "C:\Java\jdk1.4.0
\bin\javaw.exe" with whatever path is correct on your
machine.
IMPORTANT: include the double quotes to take care of names
with spaces.
If you are using something other than Windows and you know
how to set up an association in your OS, please contact me.  |
| Jabez |
| |
| |
| Answer | yes  |
| Nitin Gupta [IGNOU] |
| |
| |
| Answer | Jabez is correct, but I also think it is wise to note that
most of the newer java installers will set up the JAR
association for double clicking within explorer
automatically.
don't forget to add the java bin folder to your Path
environmental Variable!  |
| Michael Gooch [IGNOU] |
| |
| |
| Question |
how to print a message to console without using main()
function?(do not use even static blocks also.) |
Rank |
Answer Posted By |
|
Question Submitted By :: Rajavardhan Reddy K |
| This Interview Question Asked @ Google |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | using a static block you can print the message (string)s.o.p  |
| Narender |
| |
| |
| Answer | use a constructor and declare a global object.
class message
{
public:
message("Hello world\n");
}a;
void main(){}  |
| Vijay Nag |
| |
| |
| Answer | class testing{
public testing(){
System.out.println("Hello ");
}
}
public class TestClass{
static testing t = new testing();
public TestClass(){
}
}  |
| Cvs |
| |
| |
| Answer | class testprint
{
static String print=testprint.toString("test");
public static String toString(String s)
{
System.out.println("I am Here");
return s;
}
}  |
| Amit Dubey |
| |
| |
| Answer | public class classWithoutMain {
private static int x = load();
private static int load() {
System.err.println("This message will be printed");
System.exit(0);
}
}  |
| Jaya |
| |
| |
| Answer | Sorry. Missing return statement in the former post
public class classWithoutMain {
private static int x = load();
private static int load() {
System.err.println("This message will be printed");
System.exit(0);
return 0;
}
}  |
| Jaya |
| |
| |
| Question |
How to read MS-word document in java without displaying junk
(unnecessary) data? |
Rank |
Answer Posted By |
|
Question Submitted By :: Callmevijayc |
| This Interview Question Asked @ Cognizent |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | There are lot of third party API's availbale. Please try
below one available in Jakarta site
Apache POI - HWPF - Java API to Handle Microsoft Word Files  |
| Nivas |
| |
| |
|
| |
|
Back to Questions Page |