[java]代码库
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
public class DMLReaderValues {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection connection = DriverManager
.getConnection("jdbc:odbc:practiceDatabase");
Statement statement = connection.createStatement();
ResultSet resultSet = statement
.executeQuery("select * from Catalog;");
ResultSetMetaData data = resultSet.getMetaData();
boolean b = resultSet.next();
while (b) {
for (int i = 1; i <= data.getColumnType(i); i++) {
System.out.print(resultSet.getString("编号")+" "
+ resultSet.getString("名称")+" "
+ resultSet.getString("年份")+" "
+ resultSet.getString("在架")+" "
+ resultSet.getString("作者")+" "
+ resultSet.getString("总页数")+" "
+ resultSet.getString("表演")+" "
+ resultSet.getString("格式")+" ");
b = resultSet.next();
}
System.out.println();
}
resultSet.close();
statement.close();
connection.close();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO: handle exception
System.out.println("SQLexception:" + e.getMessage());
}
}
}
初级程序员
by: 云代码会员 发表于:2016-06-09 22:57:23 顶(0) | 踩(0) 回复
我要积分啊!!!
回复评论