Javascript  
 
  ScriptJava  
 
  Perl  
 
  PHP  
 
  ROR  
 
  ask us  
 

 

Applications
  1. Getting started
  2. Definitions
  3. First program
  4. Characters and Strings
  5. Object and methods
  6. Arrays and Circles
  7. Exceptions
  8. The main method
  9. Reading
  10. Writing file
  11. Vectors
  12. Stacks
  13. Map The Dictionary
  14. Lists
  15. Linked lists
  16. Collection
  17. Interfaces
  18. Scanner
  19. StringTokenizer
  20. Generics
  21. JDBC
  22. DataBase Queries
  23. JSP, The main step

Graphics

Applets
  1. Regards
  2. One Picture
  3. Calculator
  4. Random pictures
  5. Bouncing picture

Swings
  1. Buttons listeners
  2. TextFields
  3. Swing Example

JavaBeans
  1. The first step
  2. Example

Search a word:
   



© The scientific sentence. 2010

HowTo: JDK1.5, JDK1.6, Apache2.2, Tomcat6.0, and Oracle 10g
JDBC (Java DataBase Connectivity)

/*
I. Getting ready:


Once :
- A database program is installed (We work here with Oracle database), 
- The ORACLE_HOME path is set 
(ORACLE_HOME C:\oraclexe\app\oracle\product\10.2.0\server), 
- The correct related driver jdbc (here: ojdbc14.jar) 
is downloaded and its CLASSPATH is set 
(C:\oraclexe\app\oracle\product\10.2.0\server\jdbc\lib\ojdbc14.jar;); 
The complete classpath looks like:
The related classpath is then:
CLASSPATH =.;C:\Program Files\Java\jre1.5.0_14\lib\ext\dnsns.jar;
C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\servletapi.jar;
C:\oraclexe\app\oracle\product\10.2.0\server\jdbc\lib\ojdbc14.jar;
C:\oraclexe\app\oracle\product\10.2.0\server\jlib\orai18n.jar
- The http port is set at 1521:
From SQL command line:
SQL> -- set http port and ftp port
SQL>  begin
  2  dbms_xdb.sethttpport ('1521');
  3  dbms_xdb.setftpport ('1520');
  4  end;
  5  /
SQL> quit
- A table is created and completed,
we can start connecting to the databse, sending requests, and 
getting results via Java code.


II. Test the connectivity:
*/
	import java.sql.*;
	import oracle.jdbc.*;
	import oracle.jdbc.OracleDriver;

	public class OracleConnect
	{
	public static void main(String[] args)throws SQLException
	{
	try
	{
	Class.forName("oracle.jdbc.driver.OracleDriver");	
	 Connection conn = DriverManager.getConnection("jdbc:oracle:
	thin:@HOST:1521:XE","User","Password");
	if(conn != null)
	{ System.out.println("I am Connected to oracle database");
	}
	conn.close();
	} catch (Exception e) {
	System.out.println("ERROR : " + e);
	e.printStackTrace(System.out);
	}
	}
	}

/*
III. The main related code:

We have, generally three kind of requests:
-  execute Query();where we SELECT to return the ResultSet,
-  executeUpdate ();  where we CREATE TABLE, 
UPDATE, INSERT, DROP, or  DELETE, 
which return a confirmation digit,
-  execute(); 

The main related code is the following:

Statement stmt = conn.createStatement();
ResultSet rst = stmt.executeQuery("SELECT * (or other 
field) FROM TABLE"); or
ResultSet rst = stmt.executeUpdate ("CREATE TABLE, UPDATE, 
INSERT, DROP, or  DELETE requests");

We can therafter access to the related columns of the table by codes, 
such as:
int Value = rst.getInt(n);//get the int from the nth columun
String Data = rst.getString("Data");

And such as:
while(rst.next()){
int value = rst.getInt("culumnA");
String str = rst.getStrig ("columnB";
....
}
Finally:
ResultSet.close();
Statement.close();
Connection.close();


IV. Queries on a built Students database:
*/

	import java.sql.*;
	import oracle.jdbc.*;
	import oracle.jdbc.OracleDriver;	

	public class showTable{
	public static void main (String args []) throws SQLException
	{
	DriverManager.registerDriver (new oracle.jdbc.OracleDriver());
	Connection conn = DriverManager.getConnection("jdbc:oracle:
	thin:@HOST:1521:XE","User","Password");		
	Statement stmt = conn.createStatement();
	try {
	ResultSet rst = stmt.executeQuery( "SELECT * FROM Students 
	WHERE STUDENTID ='103' " );
	try {
	while ( rst.next() ) {
	int numColumns = rst.getMetaData().getColumnCount();
	for ( int i = 1 ; i <= numColumns ; i++ ) {//Column numbers start at 1.
	System.out.println( "COLUMN " + i + " = " + rst.getObject(i) );
	}
	System.out.println();
	}
	} finally {
	rst.close();
	}
	} finally {
	stmt.close();
	}
	}
	}// End of class showtable


  
Google
Web
ScientificSentence
 




chimie labs
|
scientific sentence
|
java
|
php
|
green cat
|
contact
|


© Scientificsentence 2009. All rights reserved.