java当中请给出一个oracle的helloworld例子
[学习笔记]
2.oracle的helloworld例子:
import java.sql.*;
public class oraclehello{
public static void main(string args[]) {
connection con;
string createstring;
createstring = "select empno from emp";
statement stmt;
try {
/*see above, import sun.jdbc.odbc.jdbcodbcdriver;*/
/*see above, import sun.jdbc.odbc.jdbcodbcdriver;for kkk this kind of url connection string, you must
use sun.jdbc.odbc.jdbcodbcdriver. if you wan to use oracle.jdbc.driver.oracledriver, you must use
jdbc:oracle:thin:@localhost:1521:qixy */
/*a sound blaster hardware need a driver to function, software draw awave, then when play,
through the driver, hardware can change it to sound you can hear. here your statement can
be sent to the database.
public static class forname(string classname)
throws classnotfoundexceptionreturns the class object associated with the class or interface with the given string name. invoking this method is equivalent to:
class.forname(classname, true, currentloader)
where currentloader denotes the defining class loader of the current class.
for example, the following code fragment returns the runtime class descriptor for the class named java.lang.thread:
class t = class.forname("java.lang.thread")
a call to forname("x") causes the class named x to be initialized.
*/
class.forname("oracle.jdbc.driver.oracledriver");
con = drivermanager.getconnection("jdbc:oracle:thin:@localhost:1521:qixy", "scott", "tiger");
system.out.println("connection is ok");
stmt = con.createstatement();
// stmt.execute(createstring);
resultset rs=stmt.executequery(createstring);
while(rs.next())
{ string no=rs.getstring("empno");
system.out.println(no);
}
stmt.close();
con.close(); }
catch (exception ex) {
ex.printstacktrace();
} }}
文章转载自原文:
推荐阅读
-
java当中JDBC当中请给出一个Oracle DataSource and SingleTon例子
-
java当中JDBC当中请给出一个sql server的dataSource的helloworld例子
-
java当中JDBC当中请给出一个SQLServer DataSource and SingleTon例子
-
java中给出一个主线程要join子线程的例子
-
java中给出一个子线程如何捕获主线程异常的例子
-
java当中请给出一个oracle的helloworld例子
-
给出一个javascript的Helloworld例子
-
java当中JDBC当中请给出一个sql server的stored procedure例子
-
请给出一个Scala RDD的HelloWorld例子
-
java当中JDBC当中请给出一个SQLServer DataSource and SingleTon例子