日期:2014-05-16  浏览次数:20362 次

一 JDBC
public static final String DBDRIVE = "oracle.jdbc.driver.OracleDriver";
	 public static final String DBURL = "jdbc:oracle:thin:@169.254.24.29:1521:orcl";
	 public static final String DBUSER = "scott";
	 public static final String DBPASSWORD= "tiger";
	 public static void main(String[] args) {
		Connection conn =null;
		PreparedStatement pstmt = null;
		try {
			Class.forName(DBDRIVE);
		conn = DriverManager.getConnection(DBURL, DBUSER, DBPASSWORD);
		String sql = "insert into student values(?,?)";
		pstmt = conn.prepareStatement(sql);
		pstmt.setString(1, "球星");
		pstmt.setString(2, "5656");
		pstmt.executeUpdate();
		pstmt.close();
		conn.close();		
		}
		catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}