从事IT基础架构多年,发现自己原来更合适去当老师……喜欢关注新鲜事物,不仅限于IT领域。
分类: Oracle
2007-08-01 13:25:16
In this Document
Proofread this sample code before using it! Due to the differences in the way text editors, e-mail packages and operating systems handle text formatting (spaces, tabs and carriage returns), this sample code may not be in an executable state when you first receive it. Check over the sample code to ensure that errors of this type are corrected.
import java.sql.*;
public class TestJdbc {
public static void main (String[] args) {
if (args.length < 3) {
System.out.println("Usage: java TestJdbc jdbcUrl user password");
System.exit(0);
}
String url = args[0];
String user = args[1];
String password = args[2];
try {
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection conn = DriverManager.getConnection(url, user, password);
DatabaseMetaData meta = conn.getMetaData ();
// gets driver info:
System.out.println("\n=============\nDatabase Product Name is ... " +
meta.getDatabaseProductName());
System.out.println("\nDatabase Product Version is " +
meta.getDatabaseProductVersion());
System.out.println("\n=============\nJDBC Driver Name is ........ " +
meta.getDriverName());
System.out.println("\nJDBC Driver Version is ..... " + meta.getDriverVersion());
System.out.println("\nJDBC URL " + meta.getURL());
System.out.println("\n=============");
//get environment info:
java.util.Properties props = System.getProperties();
java.util.Enumeration propNames = props.propertyNames();
StringBuffer path = new StringBuffer("\t" + props.getProperty("java.library.path"));
int idx = 0;
while (idx < path.length()) {
idx = path.toString().indexOf(";", idx);
if (idx == -1)
break;
path.replace(idx, ++idx, "\n\t");
idx++;
}
StringBuffer classpath = new StringBuffer("\t" + props.getProperty("java.class.path"));
int idx2 = 0;
while (idx2 < classpath.length()) {
idx2 = classpath.toString().indexOf(";", idx2);
if (idx2 == -1)
break;
classpath.replace(idx2, ++idx2, "\n\t");
idx2++;
}
System.out.println("java runtime Version: \t" +
props.getProperty("java.runtime.version") + "\n");
System.out.println("\n=============");
System.out.println("java vm Version: \t" + props.getProperty("java.vm.version") + "\n");
System.out.println("\n=============");
System.out.println("java vm name: \t" + props.getProperty("java.vm.name") + "\n");
System.out.println("\n=============");
System.out.println("java library path: \n" + path + "\n");
System.out.println("\n=============");
System.out.println("java classpath: " + classpath + "\n");
} catch (Exception e) {e.printStackTrace(); }
}//end of main
}//end of TestJdbc
=============
Database Product Name is ... Oracle
Database Product Version is Oracle9i Enterprise Edition Release 9.2.0.4.0 - Pro
duction
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production
=============
JDBC Driver Name is ........ Oracle JDBC driver
JDBC Driver Version is ..... 9.2.0.4.0
Jdbc URL java:oracle:thin:@myhost:1521:mysid
=============
java runtime Version: 1.3.1_09-b03
=============
java vm Version: 1.3.1_09-b03
=============
java vm name: Java HotSpot(TM) Client VM
=============
java library path:
c:\java\jdk1.3\bin
.
C:\WINNT\system32
C:\WINNT
C:\oracle\ora92\bin
C:\ora9ias\bin
C:\ora9ias\jlib
C:\oracle\ora817\bin
C:\oracle\ora817\Apache\Perl\5.00503\bin\mswin32-x86
C:\Program Files\Oracle\jre\1.1.7\bin
c:\java\jdk1.3\bin
C:\Program Files\Oracle\jre\1.3.1\bin
C:\Program Files\Oracle\jre\1.1.8\bin
C:\Program Files\Reflection
C:\WINNT\system32
C:\WINNT
C:\WINNT\System32\Wbem
C:\Program Files\Symantec\pcAnywhere\
C:\Program Files\Microsoft Visual Studio\Common\Tools\WinNT
C:\Program Files\Microsoft Visual Studio\Common\MSDev98\Bin
C:\Program Files\Microsoft Visual Studio\Common\Tools
C:\Program Files\Microsoft Visual Studio\VC98\bin
=============
java classpath: .
c:\oracle\ora92\jdbc\lib\classes12.jar
c:\oracle\ora92\lib\xmlparserv2.jar
c:\oracle\ora92\rdbms\jlib\xdb.jar