日期:2014-05-17 浏览次数:20779 次
try { Class.forName("oracle.jdbc.driver.OracleDriver"); String url = "jdbc:oracle:thin:@localhost:1521:orcl"; String user = "yongning"; String password = "yongning"; Connection conn = DriverManager.getConnection(url,user,password); DatabaseMetaData dmd = conn.getMetaData(); System.out.println(dmd.getDatabaseMajorVersion()); System.out.println(dmd.getDatabaseProductName()); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("select * from test_book1"); ResultSetMetaData rsmd = rs.getMetaData(); int columnCount = rsmd.getColumnCount(); System.out.println(columnCount);// for(int i = 1; i <= columnCount; i++){ //把列名打印在一行,每个列名之间间隔一个制表位(\t) System.out.print(rsmd.getColumnName(i)+"\t"); } System.out.println(); System.out.println("-----------------------------"); while(rs.next()){ //数据表的一行 System.out.println("奶奶的,就是不给我输出"); for(int i = 1; i <= columnCount; i++){ //一行中的每个列 System.out.print(rs.getString(rsmd.getColumnName(i)) + "\t"); } System.out.println(); } }catch(Exception e){ e.printStackTrace(); } }
create table test_book1(id number,bookname varchar(64)); insert into test_book1 values('1','我我我'); select * from test_book1; ID BOOKNAME ----- ------------------------- 1 我我我