[学习笔记]
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中的BigInteger和 BigDecimal,再也不怕面试了
tomact正常启动,但是在日志文件报错java.lang.NoClassDefFoundError: java/util/logging/Logger
servlet整合quartz:servlet中使用quartz,服务器启动时加载任务
荐 Java——集合中的Map接口通过HashMap类实现一些常用的方法
SpringBoot整合mybatis访问时报错Invalid bound statement (not found)
网友评论