标签:oid on() except cot rom main import cep return
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("连接数据库成功!");
}else{
System.out.println("连接数据库失败!");
}
} 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();
//查询
String name =jdb.query();
System.out.println("==="+name);
}
}
jdbc连接oracle11g的问题——查不出来数据,权限问题
标签:oid on() except cot rom main import cep return
原文地址:http://www.cnblogs.com/xjcheng1/p/7086588.html