当前位置: 技术问答>java相关
JBUILDER 编写的程序如何连接oracle数据库?
来源: 互联网 发布时间:2015-10-25
本文导语: 我在configure libraries里的userhome下增加了一个类设置(jdbc for oracle的路)径,然后在我项目的属性里的paths/required libraries里加上了刚才的设置,可是连接总是不成功?难道我下在的jdbc for oracle有问题?帮帮我! ...
我在configure libraries里的userhome下增加了一个类设置(jdbc for oracle的路)径,然后在我项目的属性里的paths/required libraries里加上了刚才的设置,可是连接总是不成功?难道我下在的jdbc for oracle有问题?帮帮我!
|
import java.io.*;
import java.sql.*;
import java.util.*;
public class JDBCtest{
public static void main(String args[]){
//上面两个括号
Vector drivers = new Vector();
Connection con;
String driverClassName = "oracle.jdbc.driver.OracleDriver";
String URL = "jdbc:oracle:thin:@172.16.58.160:1521:orc1";
String user = "test2";
String password = "test2";
try { //注册数据库驱动
Driver driver = (Driver)Class.forName(driverClassName).newInstance();
DriverManager.registerDriver(driver);
drivers.addElement(driver);
System.out.println("Registered JDBC driver " + driverClassName);
}
catch (Exception e) {
System.out.println("Can't register JDBC driver: " +
driverClassName + ", Exception: " + e);
}
try { //创建连接
if (user == null) {
con = DriverManager.getConnection(URL);
}
else {
con = DriverManager.getConnection(URL,user,password);
}
System.out.println("Created a new connection in pool " + user);
String sql = "select * from sms_mo";
Statement stmt = null;
for(int i=0; i
import java.sql.*;
import java.util.*;
public class JDBCtest{
public static void main(String args[]){
//上面两个括号
Vector drivers = new Vector();
Connection con;
String driverClassName = "oracle.jdbc.driver.OracleDriver";
String URL = "jdbc:oracle:thin:@172.16.58.160:1521:orc1";
String user = "test2";
String password = "test2";
try { //注册数据库驱动
Driver driver = (Driver)Class.forName(driverClassName).newInstance();
DriverManager.registerDriver(driver);
drivers.addElement(driver);
System.out.println("Registered JDBC driver " + driverClassName);
}
catch (Exception e) {
System.out.println("Can't register JDBC driver: " +
driverClassName + ", Exception: " + e);
}
try { //创建连接
if (user == null) {
con = DriverManager.getConnection(URL);
}
else {
con = DriverManager.getConnection(URL,user,password);
}
System.out.println("Created a new connection in pool " + user);
String sql = "select * from sms_mo";
Statement stmt = null;
for(int i=0; i