JDBC Connection oracle11g problem-data not found, permissions issues

Source: Internet
Author: User
Tags stmt

Package com.sdk;

Import java.sql.Connection;
Import Java.sql.DriverManager;
Import java.sql.PreparedStatement;
Import Java.sql.ResultSet;
Import java.sql.SQLException;

public class JDBC {

String driverclass= "Oracle.jdbc.driver.OracleDriver";
Connection Con=null;
PreparedStatement Stmt=null;
ResultSet Rt=null;

Public Connection getconnection () {

String dburl= "JDBC:ORACLE:THIN:@192.168.43.181:1521:ORCL";
String dbname= "SCOTT";
String dbnpwd= "Scott";
try {
Class.forName (Driverclass);
Con=drivermanager.getconnection (Dburl, dbname, dbnpwd);
if (con!=null) {
SYSTEM.OUT.PRINTLN ("Connection database succeeded! ");
}else{
SYSTEM.OUT.PRINTLN ("Connection database failed! ");
}
} catch (SQLException e) {
E.printstacktrace ();
} catch (ClassNotFoundException e) {
E.printstacktrace ();
}
return con;
}

Public String query () {
con = getconnection ();
String sql= "SELECT * from Tbl_stu";
String Name=null;
try {
Stmt=con.preparestatement (SQL);

Rt=stmt.executequery ();
while (Rt.next ()) {
Name=rt.getstring ("Sid");
System.out.println ("#####" +name);
}
} catch (SQLException e) {
E.printstacktrace ();
}finally{
if (con!=null| | stmt!=null| | Rt!=null) {
try {
Con.close ();

} catch (SQLException e) {
E.printstacktrace ();
}

}

}
return name;
}


public static void Main (string[] args) {

JDBC jdb=new jdbc ();
Inquire
String name =jdb.query ();
System.out.println ("= = =" +name);
}

}

JDBC Connection oracle11g problem-data not found, permissions issues

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.