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