Oracle uses JDBC for additional pruning checks

Source: Internet
Author: User

Oracle uses JDBC for additional pruning checks

Databases and tables

TableUSERS
(
USERNAMEVARCHAR2(20)  not < Span style= "color: #0000ff;" >null,
  PASSWORD  varchar2 20)
)
altertable users
  add constraint  u_pk primary  key  (USERNAME)


/**
* Jdbcexample.java
*
* provider:coderdream ' s Studio
*
* History
* Date (dd/mm/yyyy) Author Description
* ----------------------------------------------------------------------------
* APR, Coderdream Created
*/

PackageCom.coderdream.jdbc.oracle;

ImportJava.sql.Connection;
ImportJava.sql.DriverManager;
ImportJava.sql.PreparedStatement;
ImportJava.sql.ResultSet;
ImportJava.sql.SQLException;
ImportJava.sql.Statement;

/**
*@authorXl
*
*/
PublicClassJdbcexample {


Private StaticConnection Getconn () {
String Driver="Oracle.jdbc.driver.OracleDriver";
String URL="Jdbc:oracle:thin:@10.5.15.117:1521:csi";
String username="Scott";
String Password="Tiger";
Connection Conn=Null;
Try{
Class.forName (driver);
//New Oracle.jdbc.driver.OracleDriver ();
Conn=Drivermanager.getconnection (URL, username, password);
}
Catch(ClassNotFoundException e) {
E.printstacktrace ();
}
Catch(SQLException e) {
E.printstacktrace ();
}

ReturnConn
}

PrivateStaticIntInsert (string Username, string password) {
Connection Conn=Getconn ();
IntI=0;
String SQL="Insert into users (Username,password) values (?,?)";
PreparedStatement pstmt;
Try{
Pstmt=Conn.preparestatement (SQL);
//Statement stat = conn.createstatement ();
Pstmt.setstring (1, username);
Pstmt.setstring (2, password);
I=Pstmt.executeupdate ();
System.out.println ("Resutl:"+i);

Pstmt.close ();
Conn.close ();
}
Catch(SQLException e) {
E.printstacktrace ();
}

ReturnI
}

PrivateStaticvoidQuery () {
Connection Conn=Getconn ();
String SQL="SELECT * from Users";
PreparedStatement pstmt;
Try{
Pstmt=Conn.preparestatement (SQL);
ResultSet RS=Pstmt.executequery ();
While(Rs.next ()) {
System.out.println ("Name"+Rs.getstring ("Username")
+"\tpassword:"+Rs.getstring ("Password"));
}

Rs.close ();
Pstmt.close ();
Conn.close ();
}
Catch(SQLException e) {
E.printstacktrace ();
}

}

PrivateStaticIntUpdate (String oldname, String newpass) {
Connection Conn=Getconn ();
IntI=0;
String SQL="Update users set password= '"+Newpass
+"' Where Username= '"+Oldname+"‘";        preparedstatement pstmt;         try {            pstmt  = conn.preparestatement (SQL);             i = pstmt.executeupdate ();             system.out.println ("resutl: "  + i);             pstmt.close ();             Conn.close ();        }         catch  (sqlexception e)  {             e.printstacktrace ();        }         return i;    }        private static int delete ( String username)  {        Connection conn =  Getconn ();        int i = 0;         String sql =  "Delete users where username= '"  +  username +  "'";        preparedstatement pstmt;         try {             pstmt = conn.preparestatement (SQL);             i = pstmt.executeupdate ();             system.out.println ("resutl: "  + i);          &nbsP;  pstmt.close ();             conn.close ();         }        catch   (sqlexception e)  {             E.printstacktrace ();        }         return i;    }    /**     *   @param  args     */    public static void  main (String[] args)  {        insert ("CDE",  "123") ;         insert ("Coderdream",  "456");         query ();         update ("CoderDream",  "456 ");        query ();         delete ("CoderDream");         query ();     }}

Oracle uses JDBC for additional pruning

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.