JDBC Connects to Oracle database

Source: Internet
Author: User

Package Cn.xvl.test;import Java.sql.connection;import Java.sql.drivermanager;import java.sql.PreparedStatement; Import Java.sql.sqlexception;public class Test {public static void main (string[] args) throws ClassNotFoundException, SQL Exception {class.forname ("Oracle.jdbc.driver.OracleDriver");       Load Database driver string url= "Jdbc:oracle:thin: @localhost: 1521:xe";//connection URLString username = "root"; String password = "123456"; Connection Connection = drivermanager.getconnection (URL, username, password); String sql = "INSERT into Stu values (?)"; PreparedStatement preparestatement = connection.preparestatement (sql);p Reparestatement.setobject (1, 2); int Executeupdate = Preparestatement.executeupdate (); System.out.println (executeupdate);}}

Select value from V$parameter where name= ' instance_name '; Get oracle sid -The xe  in the above URL;

oracle Driver directory: installation directory D:\ Oracle\app\oracle\product\11.2.0\server\jdbc\lib gets the

Package cn.xvl.test;
Import Java.sql.connection;import Java.sql.drivermanager;import Java.sql.preparedstatement;import Java.sql.SQLException;
public class Test {public static void main (string[] args) throws ClassNotFoundException, SQLException {class.forname ("Ora       Cle.jdbc.driver.OracleDriver "); Load Database driver string url= "Jdbc:oracle:thin: @localhost: 1521:xe";//connection URLString username = "root"; String password = "123456"; Connection Connection = drivermanager.getconnection (URL, username, password); String sql = "INSERT into Stu values (?)"; PreparedStatement preparestatement = connection.preparestatement (sql);p Reparestatement.setobject (1, 2); int Executeupdate = Preparestatement.executeupdate (); System.out.println (executeupdate);}}

JDBC Connects to Oracle database

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.