newbie question# Java - 爪哇娇娃
w*m
1 楼
很简单,就是想测试一下jdbc conneciton
在Linux下,网上照搬一个简单的代码,然后我想用xxxxxxxx/jre/bin/java去运行
请问应该如何做?
javac Conn.java and I get Conn.class
then run Java Conn get
Exception in thread "main" java.lang.NoClassDefFoundError: Conn
at gnu.java.lang.MainThread.run(libgcj.so.7rh)
Caused by: java.lang.ClassNotFoundException: Conn not found in gnu.gcj.
runtime.SystemClassLoader{urls=[file:/apps/oracle/product/10.2.0/db_1/jdbc/
lib/], parent=gnu.gcj.runtime.ExtensionClassLoader{urls=[], parent=null}}
at java.net.URLClassLoader.findClass(libgcj.so.7rh)
at java.lang.ClassLoader.loadClass(libgcj.so.7rh)
at java.lang.ClassLoader.loadClass(libgcj.so.7rh)
at gnu.java.lang.MainThread.run(libgcj.so.7rh)
我猜是一些简单的环境设置,希望大家能指点我一下。
$more Conn.java
import java.sql.*;
class Conn {
public static void main (String[] args) throws Exception
{
Class.forName ("oracle.jdbc.OracleDriver");
Connection conn = DriverManager.getConnection
("jdbc:oracle:thin:@imdeploy:1521:SDS2009", "pstest", "pstest");
try {
Statement stmt = conn.createStatement();
try {
ResultSet rset = stmt.executeQuery("select BANNER from SYS.V_$VERSION
");
try {
while (rset.next())
System.out.println (rset.getString(1)); // Print col 1
}
finally {
try { rset.close(); } catch (Exception ignore) {}
}
}
finally {
try { stmt.close(); } catch (Exception ignore) {}
}
}
finally {
try { conn.close(); } catch (Exception ignore) {}
}
}
}
在Linux下,网上照搬一个简单的代码,然后我想用xxxxxxxx/jre/bin/java去运行
请问应该如何做?
javac Conn.java and I get Conn.class
then run Java Conn get
Exception in thread "main" java.lang.NoClassDefFoundError: Conn
at gnu.java.lang.MainThread.run(libgcj.so.7rh)
Caused by: java.lang.ClassNotFoundException: Conn not found in gnu.gcj.
runtime.SystemClassLoader{urls=[file:/apps/oracle/product/10.2.0/db_1/jdbc/
lib/], parent=gnu.gcj.runtime.ExtensionClassLoader{urls=[], parent=null}}
at java.net.URLClassLoader.findClass(libgcj.so.7rh)
at java.lang.ClassLoader.loadClass(libgcj.so.7rh)
at java.lang.ClassLoader.loadClass(libgcj.so.7rh)
at gnu.java.lang.MainThread.run(libgcj.so.7rh)
我猜是一些简单的环境设置,希望大家能指点我一下。
$more Conn.java
import java.sql.*;
class Conn {
public static void main (String[] args) throws Exception
{
Class.forName ("oracle.jdbc.OracleDriver");
Connection conn = DriverManager.getConnection
("jdbc:oracle:thin:@imdeploy:1521:SDS2009", "pstest", "pstest");
try {
Statement stmt = conn.createStatement();
try {
ResultSet rset = stmt.executeQuery("select BANNER from SYS.V_$VERSION
");
try {
while (rset.next())
System.out.println (rset.getString(1)); // Print col 1
}
finally {
try { rset.close(); } catch (Exception ignore) {}
}
}
finally {
try { stmt.close(); } catch (Exception ignore) {}
}
}
finally {
try { conn.close(); } catch (Exception ignore) {}
}
}
}