java jdbc 连接 oracle mysql

  mysql:

   Class.forName("com.mysql.jdbc.Driver").newInstance();
   Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/homework?user=root&password=123456");
   Statement sm = conn.createStatement();
   sm.executeUpdate("insert into employee(name,sex,dept,tel) VALUES('"+"小树"+"','"+"男"+"','"+"信息部门"+"','"+"13700434677"+"')");
   ResultSet rs = sm.executeQuery("select * from employee");
   while(rs.next()){
    System.out.println(rs.getString("name"));
   }

 oracle:

   // 加载驱动
   Class.forName("oracle.jdbc.driver.OracleDriver");
   // 得到连接
   ct = DriverManager.getConnection("jdbc:oracle:thin:@XWANG1.asiapacific.hpqcorp.net:1521:VINCENT","scott", "tiger");
   ct.setAutoCommit(false);
   Statement sm = ct.createStatement();

   ResultSet rs = sm.executeQuery("select * from emp where ename in ('SCOTT','SMITH')");
   while (rs.next()) {
   System.out.println("用户名:" + rs.getString("ename")"+ "          sal:" + rs.getString("sal"));

你可能感兴趣的:(oracle)