Get Parameter MetaData From Oracle JDBC Driver : Oracle JDBC : Database SQL JDBC : Java examples (example source code) Organized by topic

Java
C++
PHP
Java Home »  Database SQL JDBC   » [  Oracle JDBC  ]  Screenshots 
 



Get Parameter MetaData From Oracle JDBC Driver

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ParameterMetaData;
import java.sql.PreparedStatement;
import java.sql.Statement;

public class Main {
  public static void main(String[] argsthrows Exception {
    Connection conn = getOracleConnection();
    Statement st = conn.createStatement();
    st.executeUpdate("drop table survey;");
    st.executeUpdate("create table survey (id int,name varchar(30));");
    st.executeUpdate("insert into survey (id,name ) values (1,'nameValue')");
    
    
    PreparedStatement pstmt = null;
    ParameterMetaData paramMetaData = null;
    String query = "select * from survey where id > ? ";

    System.out.println("conn=" + conn);
    pstmt = conn.prepareStatement(query);
    paramMetaData = pstmt.getParameterMetaData();
    if (paramMetaData == null) {
      System.out.println("db vendor does NOT support ParameterMetaData");
    else {
      System.out.println("db vendor supports ParameterMetaData");
      // find out the number of dynamic parameters
      int paramCount = paramMetaData.getParameterCount();
      System.out.println("paramCount=" + paramCount);
    }

    pstmt.close();
    conn.close();

  }

  private static Connection getHSQLConnection() throws Exception {
    Class.forName("org.hsqldb.jdbcDriver");
    System.out.println("Driver Loaded.");
    String url = "jdbc:hsqldb:data/tutorial";
    return DriverManager.getConnection(url, "sa""");
  }

  public static Connection getMySqlConnection() throws Exception {
    String driver = "org.gjt.mm.mysql.Driver";
    String url = "jdbc:mysql://localhost/demo2s";
    String username = "oost";
    String password = "oost";

    Class.forName(driver);
    Connection conn = DriverManager.getConnection(url, username, password);
    return conn;
  }

  public static Connection getOracleConnection() throws Exception {
    String driver = "oracle.jdbc.driver.OracleDriver";
    String url = "jdbc:oracle:thin:@localhost:1521:caspian";
    String username = "mp";
    String password = "mp2";

    Class.forName(driver)// load Oracle driver
    Connection conn = DriverManager.getConnection(url, username, password);
    return conn;
  }
}

           
       
Download: GetParameterMetaDataFromOracleJDBCDriver.zip   ( 3,849  K )  
Related examples in the same category
1.  Get Object From Oracle Database Using STRUCTHas Download File
2.  Inser BLOG(Picture or Photo) Data Type Into Oracle DatabaseHas Download File
3.  Serialized And Deserialize Object OracleHas Download File
4.  Get Oracle Table NamesHas Download File
5.  Test Oracle JDBC Driver Installation
6.  Create Employee Table Oracle
7.  Count row in Oracle
8.  Get Column Names From ResultSet for Oracle
9.  Demo ResultSet Oracle
10.  All data types for Oracle
11.  Get Column Privileges Oracle
12.  Test OCINet 8 App
13.  Test SSL
14.  Test Data Encryption Integrity
15.  Test DataSource LookUp
16.  OracleDataSource Demo
17.  Register custome type to Oracle
18.  Insert custom type to Oracle
19.  Check JDBC Installation for Oracle
























Home| Contact Us
Copyright 2003 - 04 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.