日期:2014-05-17  浏览次数:20747 次

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");
}


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