jdbc-orcale test

package com.news.bean;

import java.sql.*;

public class Test_oracle {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
//定义变量初始化:
Connection con = null;
Statement stmt = null;
ResultSet rset = null;
PreparedStatement pStatement = null;
String sql;
System.out.println("开始测试Oracle的数据库驱动程序!");
try{
Class.forName("oracle.jdbc.driver.OracleDriver");

}
catch(ClassNotFoundException e){
System.out.println("数据库驱动类没有找到");
}
try{
con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","siyong","siyong");

System.out.println("数据库连接成功!");
sql = "select * from tb_user";
pStatement = con.prepareStatement(sql);
System.out.println("数据" + pStatement);
}catch(SQLException e)
{
System.out.println("执行SQL语句异常!");
e.printStackTrace();
}


}

}

posted on 2012-05-11 12:57  mcgee5201314  阅读(155)  评论(0)    收藏  举报