首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > oracle >

java连接数据库的有关问题, 新人!

2012-12-14 
java连接数据库的问题, 新人求助!!package com.oracle.testimport java.sql.*public class TestOracle {

java连接数据库的问题, 新人求助!!

package com.oracle.test;
import java.sql.*;


public class TestOracle {

/**
 * @param args
 */
//此程序演示对oracle的curd操作

public static void main(String[] args) {
// TODO Auto-generated method stub

//定义我们需要的变量
Connection con=null;
PreparedStatement ps=null;
ResultSet rst=null;

System.out.println("hello world");
try{
//1. 加载驱动
Class.forName("oracle.jdbc.driver.OracleDriver");
System.out.println("//1. 加载驱动");
//2. 得到连接
con=DriverManager.getConnection("jdbc:oracle:thin@127.0.0.1:1521:orcl","system","12345");
System.out.println("//2. 得到连接");
//3. 创建 preparedstatement 接口对象
ps=con.prepareStatement("select * from lijing");
System.out.println(ps);
//4. 完成查询
rst=ps.executeQuery();
//5,循环输出结果
while(rst.next()){
System.out.println(rst.getInt(1));
System.out.println("hello world");
}

}catch(Exception e){

}finally {

}
}

}



死活连接不上啊,, 
console输出只有:
hello world
//1. 加载驱动
[最优解释]
  
con=DriverManager.getConnection("jdbc:oracle:thin@127.0.0.1:1521:orcl","system","12345");

这里thin后面少了个:
[其他解释]
引用:
while(rst.next()){
System.out.println(rst.getString("name"));
System.out.println("hello world");
}


这里没有执行是为什么??


sqlplus里面执行完insert 命令之后要执行以下 commit;  不然会自动回滚
[其他解释]
 
while(rst.next()){
System.out.println(rst.getString("name"));
System.out.println("hello world");
}


这里没有执行是为什么??

热点排行