连接数据库java示例

mysql:

Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost/bbs?user=root&password=root";
Connection conn = DriverManager.getConnection(url);

Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from article");

-------------------------------------------------
oracle:

Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","tiger");

Statement stmt = conn.createStatement();
stmt.executeUpdate("insert into emp values (9999, 'YuQiuYu', 'MANAGER', NULL, to_date('2013-03-01','YYYY-MM-DD HH:MI:SS'), 9999, NULL, 10)");
   

猜你喜欢

转载自nineking.iteye.com/blog/2212738
今日推荐