标签:
我使用的是精简版的oracle。
1 导入oracle驱动包
oracle下路径
D:\oracle\app\oracle\product\11.2.0\server\jdbc\lib\ojdbc6.jar
2 查看listenerduankouhao
D:\oracle\app\oracle\product\11.2.0\server\network\ADMIN\listener.ora
3 代码
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "yu", "123");
精简版默认名为XE。
import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class jdbc { /** * @param args * @throws SQLException */ public static void main(String[] args) throws SQLException { try{ Class.forName("oracle.jdbc.driver.OracleDriver"); //new oracle.jdbc.driver.OracleDriver(); Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "yu", "123"); if(conn != null){ System.out.println("数据库连接成功!"); conn.close(); }else{ System.out.println("数据库连接失败!"); } }catch(ClassNotFoundException e){ e.printStackTrace(); } } }
标签:
原文地址:http://www.cnblogs.com/rixiang/p/4733595.html