19.09.2015 Views

Prentice.Hall.Introduction.to.Java.Programming,.Brief.Version.9th.(2014).[sharethefiles.com]

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

create table Person (<br />

firstName varchar(20),<br />

mi char(1),<br />

lastName varchar(20)<br />

)<br />

Figure 41.2<br />

The CopyFileToTable utility copies text files <strong>to</strong> database tables.<br />

Listing 41.2 gives the solution <strong>to</strong> the problem.<br />

8<br />

Listing 41.2 CopyFileToTable.java<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

import javax.swing.*;<br />

import javax.swing.border.*;<br />

import java.awt.*;<br />

import java.awt.event.*;<br />

import java.io.*;<br />

import java.sql.*;<br />

import java.util.*;<br />

public class CopyFileToTable extends JFrame {<br />

// Text file info<br />

private JTextField jtfFilename = new JTextField();<br />

private JTextArea jtaFile = new JTextArea();<br />

// JDBC and table info<br />

private JComboBox jcboDriver = new JComboBox(new String[] {<br />

"<strong>com</strong>.mysql.jdbc.Driver", "sun.jdbc.odbc.JdbcOdbcDriver",<br />

"oracle.jdbc.driver.OracleDriver"});<br />

private JComboBox jcboURL = new JComboBox(new String[] {<br />

"jdbc:mysql://localhost/javabook",<br />

"jdbc:odbc:exampleMDBDataSource",

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!