Welcome to My Infotech Blog (Read on Post's on Programming,database, and RedHat and much more) Happy Blogging, Have a pleasent Stay !
Friday, July 16, 2010
Simple Oracle Java Connection
import java.sql.*;
class oraclecon
{
public static void main(String argsp[])
{
try
{
Connection con = null;
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection("jdbc:oracle:thin:@snk:1521:database_name","scott","tiger");
Statement s=con.createStatement();
s.execute("select * from emp");
s.close();
}
catch(Exception e)
{
}
}
}
Thank You,
Tuesday, June 1, 2010
JVM Class search order
The search order for J2SDK, using the example code above, is:
-
The bootstrap classpath, which is in the sun.boot.class.path property,
-
The extension directories, which is in the java.ext.dirs property,
-
The default system classpath,
-
The current working directory,
-
The myclasses.zip file that is located in the "root" (/) file system,
-
The classes directory in the Product directory in the "root" (/) file system.
http://java.sun.com/j2se/1.4.2/docs/tooldocs/findingclasses.html
Where are all java CLASSES stored ???
Monday, April 19, 2010
Sunday, March 21, 2010
Java database connectivity
Back End : MS Access 2003
- Java Application ---> JDBC API ---> JDBC -->ODBC -->Database (MS Access)
- First u need to setup ODBC Connection to ur MS Access Database
- Then u need to connect ur JDBC to ODBC using JdbcOdbcDriver provided with Java
- Setup ODBC : first thing is go to control Panel > Administrative tools > Data Sources ODBC
- Add the database u want from List of databases
- CLick on System DSN Tab
- Add Driver For Respected Database here in out case MS Access !
- Click on Configure > click on Select > select ur DATABASE FILE
- Click on Apply Now u have successfully setup Datasource to ur database!
- REMEMBER THE NAME OF DATASOURCE ! u will need it later!
Programming Part :
- Import java.sql.*;
- Register JDBC Driver :
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- Setup Connection :
Connection con = DriverManager.getConnection("jdbc:odbc:DATASOURCE",Username,Password);
- Execute Query :
Statement stm = con.createStatement();
RecordSet rs = stm.executeQuery("QUERY HERE");
- Extract Data :
while(rs.next()) { }
- To get Value Of Data Field of type String : rs.getString()
- To get Value of Data field of type integer : rs.getInt()
- To get Value of Data Field of type Double : rs.getDouble()
- rs.close()
- stmt.close()
- con.close()
Thats It ! You Have Done !
Happy Databasing!
Friday, March 19, 2010
Monday, March 8, 2010
Capture Snapshot of PC with Current Resolution . . .(Java Programming)
//get current resolution . . .
Toolkit tk = Toolkit.getDefaultToolkit();
Dimension dm = tk.getScreenSize();
System.out.println(dm);
//Capture snapshot . . .
Robot robot = new Robot();
// Capture the screen shot of the area of the screen defined by the rectangle
BufferedImage bi=robot.createScreenCapture(new Rectangle(dm.width,dm.height));
ImageIO.write(bi, "jpg", new File("D:/imageTest.jpg"));
Wednesday, February 24, 2010
Get Operating System Name , Version , Architectur in Java
Key
Description of Associated Value
java.version
Java Runtime Environment version
java.vendor
Java Runtime Environment vendor
java.vendor.url
Java vendor URL
java.home
Java installation directory
java.vm.specification.version
Java Virtual Machine specification version
java.vm.specification.vendor
Java Virtual Machine specification vendor
java.vm.specification.name
Java Virtual Machine specification name
java.vm.version
Java Virtual Machine implementation version
java.vm.vendor
Java Virtual Machine implementation vendor
java.vm.name
Java Virtual Machine implementation name
java.specification.version
Java Runtime Environment specification version
java.specification.vendor
Java Runtime Environment specification vendor
java.specification.name
Java Runtime Environment specification name
java.class.version
Java class format version number
java.class.path
Java class path
java.library.path
List of paths to search when loading libraries
java.io.tmpdir
Default temp file path
java.compiler
Name of JIT compiler to use
java.ext.dirs
Path of extension directory or directories
os.name
Operating system name
os.arch
Operating system architecture
os.version
Operating system version
file.separator
File separator ("/" on UNIX)
path.separator
Path separator (":" on UNIX)
line.separator
Line separator ("\n" on UNIX)
user.name
User's account name
user.home
User's home directory
user.dir
Ex.
User's current working directory
osname = System.getProperty("os.name");
osversion = System.getProperty("os.version");
arch = System.getProperty("os.arch");