当前位置: 技术问答>java相关
JDBC问题,100分
来源: 互联网 发布时间:2017-03-31
本文导语: 我刚开始学习JDBC,以前开发是用WebLogic访问Oracle数据库,配置方面也是别人做好的,没什么学的。我想学学用JDK做点事情。但在做JDBC时遇到了一些问题。我的机器已经装了Oracle8.0的客户端。以下代码是否可以连接到...
我刚开始学习JDBC,以前开发是用WebLogic访问Oracle数据库,配置方面也是别人做好的,没什么学的。我想学学用JDK做点事情。但在做JDBC时遇到了一些问题。我的机器已经装了Oracle8.0的客户端。以下代码是否可以连接到数据库?如果解决不了连接问题,接下来就啥也学不了了。
Code:
import java.sql.*;
import sun.jdbc.*;
。。。。
Class.forName ("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection("jdbc:oracle:oci8:@con","scott", "tiger");
Statement stmt = conn.createStatement ();
ResultSet rset = stmt.executeQuery ("select * from tab");
while (rset.next ())
System.out.println (rset.getString (1));
但在第二行总是报错:
java.lang.UnsatisfiedLinkError: make_c_state
at oracle.jdbc.oci7.OCIDBAccess.make_c_state(Native Method)
at oracle.jdbc.oci7.OCIDBAccess.logon(OCIDBAccess.java:148)
at oracle.jdbc.driver.OracleConnection.(OracleConnection.java:103)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:148)
at java.sql.DriverManager.getConnection(DriverManager.java:517)
at java.sql.DriverManager.getConnection(DriverManager.java:199)
at study.JDBC.(JDBC.java:24)
at study.JDBC.main(JDBC.java:39)
Exception in thread "main"
我已经把Oracle自带的包classes111.jar放在Lib里了
Code:
import java.sql.*;
import sun.jdbc.*;
。。。。
Class.forName ("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection("jdbc:oracle:oci8:@con","scott", "tiger");
Statement stmt = conn.createStatement ();
ResultSet rset = stmt.executeQuery ("select * from tab");
while (rset.next ())
System.out.println (rset.getString (1));
但在第二行总是报错:
java.lang.UnsatisfiedLinkError: make_c_state
at oracle.jdbc.oci7.OCIDBAccess.make_c_state(Native Method)
at oracle.jdbc.oci7.OCIDBAccess.logon(OCIDBAccess.java:148)
at oracle.jdbc.driver.OracleConnection.(OracleConnection.java:103)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:148)
at java.sql.DriverManager.getConnection(DriverManager.java:517)
at java.sql.DriverManager.getConnection(DriverManager.java:199)
at study.JDBC.(JDBC.java:24)
at study.JDBC.main(JDBC.java:39)
Exception in thread "main"
我已经把Oracle自带的包classes111.jar放在Lib里了
|
用oracle的客户端把conn设置成数据源,用sqlplus测试用conn能连接oracle
,则上面的操作可行。
,则上面的操作可行。
|
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@con","scott", "tiger");
|
密码长度太短
|
Class.forName("oracle.jdbc.driver.OracleDriver");
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@conn:1521:orcl","scott", "tiger");
conn:服务器的机器名或者ip地址
orci:数据库服务名
试试看,你也会看得到!
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@conn:1521:orcl","scott", "tiger");
conn:服务器的机器名或者ip地址
orci:数据库服务名
试试看,你也会看得到!
|
JBUILDER内有一个专门负责连接的,可以用来测试
|
???可以用thin驱动么????