Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.SQLException;
- import javax.swing.JLabel;
- import javax.swing.JOptionPane;
- import javax.swing.JPasswordField;
- import javax.swing.JTextField;
- import oracle.jdbc.pool.OracleDataSource;
- /**
- * This class demonstrates how to use JDBC in Java, and how to use * transactions.
- *
- * @author eleal *
- */
- public class JDBCExample {
- String jdbcUrl = "jdbc:oracle:thin:@akka.d.umn.edu:1521:xe";
- // For security reasons, never PUT YOUR PASSWORD// IN YOUR SOURCE FILE LIKE THIS:
- // String password = "This is my password. Now, steal my money!";
- Connection conn;
- /**
- * This class gets the current DB connection. This is not to be used in
- * production environments. You should use a connection pool instead.
- * * @return * @throws SQLException
- */
- public Connection getDBConnection() throws SQLException{
- OracleDataSource ds = new OracleDataSource();
- ds.setURL(jdbcUrl);if(conn == null) {
- // Display a message to get the password from the user
- JLabel label = new JLabel("Oracle Username: ");
- JTextField jtf = new JTextField();
- JLabel label2 = new JLabel("Oracle Password:");
- JPasswordField jpf = new JPasswordField();
- JOptionPane.showConfirmDialog(null,new Object[]{label, jtf, label2, jpf}, "Password:",
- JOptionPane.OK_CANCEL_OPTION);
- }
- //char[] input = jpf.getPassword();
- //System.out.println(String.valueOf(input));
- String password = String.valueOf(jpf.getPassword());
- conn = ds.getConnection(jtf.getText(), password );
- conn.setAutoCommit(true);return conn;
- }
- /**
- * This is the main methods that gets called
- * @param args * @throws Exception
- */
- public static void main(String[] args) throws Exception{
- //Queries q = new Queries();
- JDBCExample a = new JDBCExample();
- a.insertProfessor();
- }
- /**
- * Query.- Insert a professor given his/her attributes *
- * @param id The id of the professor
- * @param firstName The first name of the professor
- * @param middleName The middle name of the professor
- * @param lastName The last name of the professor
- * @param degrees The degrees of the professor
- * @return * @throws SQLException
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement