java 连接oracle数据库

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public static final String drive = "oracle.jdbc.driver.OracleDriver";
public static final String url = "jdbc:oracle:thin:@10.9.34.84:1521:orcl";
public static final String DBUSER="stone";
public static final String password="123";
public  static void OracleTest()throws Exception
    {
    		// TODO Auto-generated method stub      
      Connection conn = null;//表示数据库连接
      Statement stmt= null;//表示数据库的更新
      ResultSet result = null;//查询数据库	   
      Class.forName(drive);//使用class类来加载程序
      conn =DriverManager.getConnection(url,DBUSER,password);	//连接数据库
      //Statement接口要通过connection接口来进行实例化操作
      stmt = conn.createStatement();
      //插入
      stmt.executeQuery("insert into TEST (PKNAME,STATICTIME) values('草','2014')");
     //执行SQL语句来查询数据库
//    result =stmt.executeQuery("SELECT DEPTID,DEPTNAME,ADDR,TEL,FAX,LXR,PX,UNITID FROM bs_dept");
//    			while(result.next()){//判断有没有下一行
//    				int  DEPTID =result.getInt(1);
//    				String DEPTNAME = result.getString(2);
//    				String ADDR = result.getString(3);
//    				long TEL = result.getLong(4);
//    				long FAX = result.getLong(5);
//    				String LXR =result.getString(6);
//    				int PX =result.getInt(7);
//    				int UNITID = result.getInt(8);
//    				System.out.print("DEPTID="+DEPTID+";");
//    				System.out.print("DEPTNAME="+DEPTNAME+";");
//    				System.out.print("ADDR="+ADDR+";");
//    				System.out.print("TEL="+TEL+";");
//    				System.out.print("FAX="+FAX+";");
//    				System.out.print("LXR="+LXR+";");
//    				System.out.print("PX="+PX+";");
//    				System.out.print("UNITID="+UNITID+";");
//    				System.out.println();
//    			
//    			}
    			
    			//System.out.println(conn);	
//    			result.close();//数据库先开后关
    			stmt.close();
    			conn.close();//关闭数据库
    			
    	}




 

你可能感兴趣的:(java,oracle)