Posted on 2007-08-22 10:41
semovy 阅读(507)
评论(0) 编辑 收藏 所属分类:
Oracle数据库方面
/*
java jdbc连接oracle9i
设置环境变量classpath=.;E:\oracle\ora90\jdbc\lib\classes12.zip;
*/
import java.sql.*;
public class Demo
{
public static void main(String[] args)
{
try
{
DriverManager.registerDriver(new oracle.jdbc.OracleDriver());//取其中一个即可
Class.forName("oracle.jdbc.driver.OracleDriver");
}catch(Exception e)
{
System.out.println("No Driver!");
}
try
{
String url = "jdbc:oracle:thin:@127.0.0.1:1521:demo";
String userName = "system";
String password = "manager";
Connection conn = DriverManager.getConnection(url,userName,password);
Statement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery("select * from test");
while(rset.next())
{
System.out.println("user_id: "+rset.getString("user_id"));
System.out.println("user_name: "+rset.getString("user_name"));
System.out.println("note: "+rset.getString("note"));
}
}catch(SQLException e)
{
System.out.println("can't access the database!");
}
}
}