标签:jdbc log creates import nec interface driver geturl size
package wuerer; import java.security.interfaces.RSAKey; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.Statement; import com.mysql.jdbc.DatabaseMetaData; public class YuanShu { public static void main(String[] args) throws Exception { Class.forName("com.mysql.jdbc.Driver"); Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/boooks","root","tiger"); // java.sql.DatabaseMetaData dmd= conn.getMetaData(); // System.out.println(dmd.getDriverName()); // System.out.println(dmd.getDatabaseProductName()); // System.out.println(dmd.getDatabaseProductVersion()); // System.out.println(dmd.getURL()); // System.out.println(dmd.getUserName()); Statement st=conn.createStatement(); ResultSet rs=st.executeQuery("select * from book"); ResultSetMetaData rmd=rs.getMetaData(); System.out.println("列数:"+rmd.getColumnCount()); int size=rmd.getColumnCount(); for(int i=1;i<=size;i++){ System.out.println(rmd.getColumnName(i)+","+rmd.getColumnTypeName(i)+","); } while(rs.next()){ for(int i=1;i<=size;i++){ System.out.print(rs.getObject(i)+"\t"); } System.out.println(); } conn.close(); } }
标签:jdbc log creates import nec interface driver geturl size
原文地址:http://www.cnblogs.com/zyy1130/p/6888329.html