当前位置: 技术问答>java相关
谁能帮忙提供与ORACLE连接的JAVA BEAN!谢谢!分必给!!
来源: 互联网 发布时间:2014-12-29
本文导语: 谁能帮忙提供与ORACLE连接的JAVA BEAN!谢谢!分必给!! | import java.sql.*; import java.util.*; public class openDb{ String user = "system"; String password = "manager"; String url = "jdbc:o...
谁能帮忙提供与ORACLE连接的JAVA BEAN!谢谢!分必给!!
|
import java.sql.*;
import java.util.*;
public class openDb{
String user = "system";
String password = "manager";
String url = "jdbc:oracle:thin:@192.168.0.1:1521:ORA817";//ora817为ora_sid
Connection conn = null;
ResultSet rs = null;
Statement stmt=null;
int i = 0;
//连接数据库
public openDb() {
try {
//DriverManager.setLogStream(System.out);
DriverManager.registerDriver(
new oracle.jdbc.driver.OracleDriver());
//DriverManager.setLoginTimeout(10);
//DriverManager.setLogStream(System.out);
conn = DriverManager.getConnection(url, user, password);
stmt = conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_UPDATABLE);
}
catch(Exception e)
{
e.printStackTrace();
}
}
//执行查询返回为记录
public ResultSet executeQuery(String sql)
{
ResultSet rs=null;
try
{
rs = stmt.executeQuery(sql);
}
catch(SQLException e)
{
System.err.println("query(): " + e.getMessage());
}
return rs;
}
//关闭连接
public void cls()
{
try
{
stmt.close();
conn.close();
}
catch(SQLException e)
{
System.err.println("query(): " + e.getMessage());
}
}
}
import java.util.*;
public class openDb{
String user = "system";
String password = "manager";
String url = "jdbc:oracle:thin:@192.168.0.1:1521:ORA817";//ora817为ora_sid
Connection conn = null;
ResultSet rs = null;
Statement stmt=null;
int i = 0;
//连接数据库
public openDb() {
try {
//DriverManager.setLogStream(System.out);
DriverManager.registerDriver(
new oracle.jdbc.driver.OracleDriver());
//DriverManager.setLoginTimeout(10);
//DriverManager.setLogStream(System.out);
conn = DriverManager.getConnection(url, user, password);
stmt = conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_UPDATABLE);
}
catch(Exception e)
{
e.printStackTrace();
}
}
//执行查询返回为记录
public ResultSet executeQuery(String sql)
{
ResultSet rs=null;
try
{
rs = stmt.executeQuery(sql);
}
catch(SQLException e)
{
System.err.println("query(): " + e.getMessage());
}
return rs;
}
//关闭连接
public void cls()
{
try
{
stmt.close();
conn.close();
}
catch(SQLException e)
{
System.err.println("query(): " + e.getMessage());
}
}
}
|
import java.sql.*;
public class oradb {
String orauser="user";
String orapasswd="pwd";
String sDBDriver="oracle.jdbc.driver.OracleDriver";
String sConnStr="jdbc:oracle:thin:@127.0.0.1:1521:ORCL";
private Connection conn = null;
private Statement stmt = null;
ResultSet rs = null;
public oradb() {
try {
Class.forName(sDBDriver);
}
catch(java.lang.ClassNotFoundException e) {
System.err.println("oradb(): " + e.getMessage());
}
}
public ResultSet executeQuery(String sql) {
rs = null;
try {
conn = DriverManager.getConnection(sConnStr,orauser,orapasswd);
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}
catch(SQLException ex) {
System.err.println("aq.executeQuery: " + ex.getMessage());
}
return rs;
}
public void executeUpdate(String sql) {
stmt = null;
rs=null;
try {
conn = DriverManager.getConnection(sConnStr,orauser,orapasswd);
stmt = conn.createStatement();
stmt.executeQuery(sql);
stmt.close();
conn.close();
}
catch(SQLException ex) {
System.err.println("aq.executeQuery: " + ex.getMessage());
}
}
public void closeStmt(){
try{
stmt.close();
}
catch(SQLException e){
e.printStackTrace();
}
}
public void closeConn(){
try{
conn.close();
}
catch(SQLException e){
e.printStackTrace();
}
}
}
public class oradb {
String orauser="user";
String orapasswd="pwd";
String sDBDriver="oracle.jdbc.driver.OracleDriver";
String sConnStr="jdbc:oracle:thin:@127.0.0.1:1521:ORCL";
private Connection conn = null;
private Statement stmt = null;
ResultSet rs = null;
public oradb() {
try {
Class.forName(sDBDriver);
}
catch(java.lang.ClassNotFoundException e) {
System.err.println("oradb(): " + e.getMessage());
}
}
public ResultSet executeQuery(String sql) {
rs = null;
try {
conn = DriverManager.getConnection(sConnStr,orauser,orapasswd);
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}
catch(SQLException ex) {
System.err.println("aq.executeQuery: " + ex.getMessage());
}
return rs;
}
public void executeUpdate(String sql) {
stmt = null;
rs=null;
try {
conn = DriverManager.getConnection(sConnStr,orauser,orapasswd);
stmt = conn.createStatement();
stmt.executeQuery(sql);
stmt.close();
conn.close();
}
catch(SQLException ex) {
System.err.println("aq.executeQuery: " + ex.getMessage());
}
}
public void closeStmt(){
try{
stmt.close();
}
catch(SQLException e){
e.printStackTrace();
}
}
public void closeConn(){
try{
conn.close();
}
catch(SQLException e){
e.printStackTrace();
}
}
}
|
package person;
import java.sql.*;
import java.io.*;
import java.util.*;
//import java.servlet.*;
//import java.servlet.http.*;
public class personbean_1
{
String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String sConnStr = "jdbc:odbc:test";
Connection conn = null;
ResultSet rs = null;
public personbean_1()
{
try
{
Class.forName(sDBDriver);
}
catch(java.lang.ClassNotFoundException e)
{
System.err.println("personbean(): " + e.getMessage());
}
}
public ResultSet executeQuery ( String sql)
{
rs = null;
try
{
conn=DriverManager.getConnection(sConnStr,"dongdong","dongdong");
Statement stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}
catch (SQLException ex)
{
System.err.println("aq.executeQuery: " + ex.getMessage());
}
return rs;
}
public char get_the_char (String my_string,int location)
{
return my_string.charAt(location);
}
}
import java.sql.*;
import java.io.*;
import java.util.*;
//import java.servlet.*;
//import java.servlet.http.*;
public class personbean_1
{
String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String sConnStr = "jdbc:odbc:test";
Connection conn = null;
ResultSet rs = null;
public personbean_1()
{
try
{
Class.forName(sDBDriver);
}
catch(java.lang.ClassNotFoundException e)
{
System.err.println("personbean(): " + e.getMessage());
}
}
public ResultSet executeQuery ( String sql)
{
rs = null;
try
{
conn=DriverManager.getConnection(sConnStr,"dongdong","dongdong");
Statement stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}
catch (SQLException ex)
{
System.err.println("aq.executeQuery: " + ex.getMessage());
}
return rs;
}
public char get_the_char (String my_string,int location)
{
return my_string.charAt(location);
}
}