Advertisement
Guest User

Untitled

a guest
Apr 16th, 2019
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.PreparedStatement;
  3. import java.sql.SQLException;
  4. import javax.swing.JLabel;
  5. import javax.swing.JOptionPane;
  6. import javax.swing.JPasswordField;
  7. import javax.swing.JTextField;
  8. import oracle.jdbc.pool.OracleDataSource;
  9. /**
  10. * This class demonstrates how to use JDBC in Java, and how to use * transactions.
  11. *
  12. * @author eleal *
  13. */
  14.  
  15. public class JDBCExample {
  16. String jdbcUrl = "jdbc:oracle:thin:@akka.d.umn.edu:1521:xe";
  17. // For security reasons, never PUT YOUR PASSWORD// IN YOUR SOURCE FILE LIKE THIS:
  18. // String password = "This is my password. Now, steal my money!";
  19. Connection conn;
  20. /**
  21. * This class gets the current DB connection. This is not to be used in
  22. * production environments. You should use a connection pool instead.
  23. * * @return * @throws SQLException
  24. */
  25. public Connection getDBConnection() throws SQLException{
  26. OracleDataSource ds = new OracleDataSource();
  27.  
  28.  
  29. ds.setURL(jdbcUrl);if(conn == null) {
  30. // Display a message to get the password from the user
  31. JLabel label = new JLabel("Oracle Username: ");
  32. JTextField jtf = new JTextField();
  33. JLabel label2 = new JLabel("Oracle Password:");
  34. JPasswordField jpf = new JPasswordField();
  35. JOptionPane.showConfirmDialog(null,new Object[]{label, jtf, label2, jpf}, "Password:",
  36. JOptionPane.OK_CANCEL_OPTION);
  37. }
  38. //char[] input = jpf.getPassword();
  39. //System.out.println(String.valueOf(input));
  40. String password = String.valueOf(jpf.getPassword());
  41. conn = ds.getConnection(jtf.getText(), password );
  42. conn.setAutoCommit(true);return conn;
  43. }
  44.  
  45. /**
  46. * This is the main methods that gets called
  47. * @param args * @throws Exception
  48. */
  49. public static void main(String[] args) throws Exception{
  50. //Queries q = new Queries();
  51. JDBCExample a = new JDBCExample();
  52. a.insertProfessor();
  53. }
  54. /**
  55. * Query.- Insert a professor given his/her attributes *
  56. * @param id The id of the professor
  57. * @param firstName The first name of the professor
  58. * @param middleName The middle name of the professor
  59. * @param lastName The last name of the professor
  60. * @param degrees The degrees of the professor
  61. * @return * @throws SQLException
  62. */
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement