Danh mục

Java Database Programming Bible- P6

Số trang: 50      Loại file: pdf      Dung lượng: 1.40 MB      Lượt xem: 19      Lượt tải: 0    
Hoai.2512

Xem trước 5 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Java Database Programming Bible- P6: Welcome to Java Database Programming Bible. This book is for readers who are alreadyfamiliar with Java, and who want to know more about working with databases. The JDBCApplication Programming Interface has made database programming an importantaspect of Java development, particularly where Web applications are concerned.
Nội dung trích xuất từ tài liệu:
Java Database Programming Bible- P6 Chapter 7:Retrieving Data with SQL Queries * CREATE statements */ class TableQueryFrame extends JInternalFrame{ protected JTable table; protected JScrollPane tableScroller; protected JTextArea SQLPane = new JTextArea(); protected JButton queryButton = new JButton(Execute Query); protected DatabaseUtilities dbUtils; protected String tableName = null; protected String colNames[] = null; protected String dataTypes[] = null; protected String SQLQuery = null; protected String SQLCommandRoot = ; Y FL public TableQueryFrame(String tableName, DatabaseUtilities dbUtils){ AM System.out.println(tableName+, +dbUtils); setSize(600,400); setLocation(10,10); TE setClosable(true); setMaximizable(true); setIconifiable(true); setResizable(true); getContentPane().setLayout(new BorderLayout()); this.tableName=tableName; this.dbUtils=dbUtils; setTitle(Query +tableName); init(); setVisible(true); } // initialize the JInternalFrame private void init(){ -249 - Team-Fly®Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Chapter 7:Retrieving Data with SQL Queries colNames = dbUtils.getColumnNames(tableName); dataTypes = dbUtils.getDataTypes(tableName); SQLQuery = SELECT TOP 5 * FROM +tableName; Vector dataSet = dbUtils.executeQuery(SQLQuery); table = createTable(colNames,dataSet); JScrollPane sqlScroller = new JScrollPane(SQLPane); tableScroller = new JScrollPane(table); JSplitPane splitter = new JSplitPane(JSplitPane.VERTICAL_SPLIT, sqlScroller,tableScroller); splitter.setDividerLocation(100); getContentPane().add(splitter,BorderLayout.CENTER); getContentPane().add(queryButton,BorderLayout.SOUTH); queryButton.addActionListener(new ButtonListener()); } protected JTable createTable(String[] colNames,Vector dataSet){ int nRows = dataSet.size(); String[][] rowData = new String[nRows][colNames.length]; for(int i=0;i Chapter 7:Retrieving Data with SQL Queries viewport.add(table); } } } Changes to the DBManager class (Listing 7-4) are once again minimal, amounting to no more than adding the hooks for the menu. Listing 7-4: DBManager package jdbc_bible.part2; import java.awt.*; import java.awt.event.*; import java.util.Vector; import javax.swing.*; import javax.swing.event.*; public class DBManager extends JFrame{ JMenuBar menuBar = new JMenuBar(); JDesktopPane desktop = new JDesktopPane(); String database = null; String tableName = null; String menuSelection = null; TableBuilderFrame tableMaker = null; TableEditFrame tableEditor = null; // added for Chapter 6 TableQueryFrame tableQuery = null; // added for Chapter 7 DatabaseUtilities dbUtils = null; TableMenu tableMenu = new TableMenu(); EditMenu editMenu = new EditMenu(); // added for Chapter 6 ViewMenu viewMenu = new ViewMenu(); // added for Chapter 7 MenuListener menuListener = new MenuListener(); public DBManager(){ -251 -Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Chapter 7:Retrieving Data with SQL Queries setJMenuBar(menuBar); setTitle(Java Database Bible); getC ...

Tài liệu được xem nhiều:

Tài liệu cùng danh mục:

Tài liệu mới: