Welcome to Dream.In.Code
Getting Java Help is Easy!

Join 109,297 Java Programmers for FREE! Ask your question and get quick answers from experts. There are 1,203 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



Java connecting with an ODBC

 
Reply to this topicStart new topic

> Java connecting with an ODBC, JDBC

eXceed69
Group Icon



post 26 Nov, 2006 - 10:56 PM
Post #1


Java Database Connectivity (JDBC) supports ODBC-based databases and provides a independent database.

JDBC has four primary pieces, used for each database access phase:

• DriverManager: the DriverManager class loads and configures a database driver on the database
• Connection: the Connection class performs confectioning and authentication to a database

CODE

getConnection(String url)
getConnection(String url, Properties info)
getConnection(String url, String eXceed, String 12345)


The usual password and username of a database especially the oracle

CODE

Connection conn = DriverManager.getConnection( "jdbc:oracle:thin:@mydbserver:1521:mysid","scott", "tiger" );


• Statement / PreparedStatement: the Statement and PreparedStatement classes send SQL statements to the database engine for preprocessing and eventually execution
CODE

Statement createStatement()
Statement createStatement(int resultSetType, int resultSetConcurrency)


…..

CODE

PreparedStatement prepareStatement(String sql)
PreparedStatement prepareStatement(String sql,
int resultSetType, int resultSetConcurrency)


• ResultSet: the ResultSet class allows for the inspection of results from executions

CODE
      
ResultSet rs = preparedStatement.executeQuery();



Here some sample code for you:

CODE


package com.informit.jdbc;

import java.sql.*;

public class JDBCExample {
  public static void main( String[] args ) {
   try {
     DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
     Connection conn = DriverManager.getConnection(
"jdbc:oracle:thin:@mydbserver:1521:mysid",
                            "exceed", "12345" );

     // Create a Statement
     PreparedStatement ps = conn.prepareStatement(
"SELECT state FROM HomePage WHERE name = ?" );
     ps.setString( 1, "Ronald" );

     ResultSet rs = ps.executeQuery();
     // Iterate through the result and print the employee names
     while (rs.next ()) {
      System.out.println( "State: " + rs.getString( "state" ) );
     }
   }
   catch( Exception e ) {
     e.printStackTrace();
   }
  }
}




here some more example links for you:

Getting Started with JDBC

Java Database Connectivity



For more example here are some links for you:
Sample Code

This post has been edited by eXceed69: 10 Dec, 2006 - 09:10 PM
Go to the top of the page
+Quote Post


Register to Make This Ad Go Away!

born2c0de
Group Icon



post 5 Dec, 2006 - 01:14 AM
Post #2
Don't forget to make the changes, exceed69.

Good Day.
Go to the top of the page
+Quote Post

eXceed69
Group Icon



post 8 Dec, 2006 - 03:32 AM
Post #3
just update it Born2Code..Lol
Go to the top of the page
+Quote Post

Dark_Nex
*



post 22 Dec, 2006 - 01:47 AM
Post #4
what a lovely girl....thanks for it...it will be a reference for my progress...hope see yah here biggrin.gif
Go to the top of the page
+Quote Post


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 9/6/08 09:44AM

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month