Skip to content

Instantly share code, notes, and snippets.

View darbyluv2code's full-sized avatar

Chad Darby darbyluv2code

View GitHub Profile
@darbyluv2code
darbyluv2code / gist:190193afe61fce97c3f7
Created April 10, 2015 14:53
UserDAO.addUser(...) method - How to create encrypted passwords in the database
package com.luv2code.jdbc.employeesearch.dao;
import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
@darbyluv2code
darbyluv2code / EmployeeSearchApp.java
Created April 21, 2015 21:47
User names are populated in lines 64-69
package com.luv2code.jdbc.employeesearch.ui;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
create database if not exists demo;
use demo;
drop table if exists employees;
CREATE TABLE `employees` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`last_name` varchar(64) DEFAULT NULL,
`first_name` varchar(64) DEFAULT NULL,
@darbyluv2code
darbyluv2code / Driver.java
Created September 30, 2016 13:57
Watching files in Java with WatchService
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardWatchEventKinds;
import java.nio.file.WatchEvent;
import java.nio.file.WatchKey;
import java.nio.file.WatchService;
import java.util.List;
public class Driver {
@darbyluv2code
darbyluv2code / Student.java
Created October 3, 2016 14:32
FAQ: How to populate radiobuttons with items from Java class like we did with selectlist?
package com.luv2code.springdemo.mvc;
import java.util.LinkedHashMap;
public class Student {
private String firstName;
private String lastName;
private String favoriteLanguage;
CREATE TABLE `employees` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`last_name` varchar(64) DEFAULT NULL,
`first_name` varchar(64) DEFAULT NULL,
`checkout_time` timestamp DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
String sql = "INSERT INTO employees (last_name, first_name, checkout_time) values (?, ?, ?)";
PreparedStatement myStmt = myConn.prepareStatement(sql);
...
java.util.Date now = new java.util.Date();
java.sql.Timestamp currentTimetamp = new java.sql.Timestamp(now.getTime());
myStmt.setTimestamp(3, currentTimestamp);
myStmt.executeUpdate();
String sql = "select * from employees";
ResultSet myRs = myStmt.executeQuery(sql);
while (myRs.next()) {
System.out.println(myRs.getTimestamp("checkout_time"));
}
<!DOCTYPE html>
<html>
<head>
<title>Add Student</title>
<link type="text/css" rel="stylesheet" href="css/style.css">
<link type="text/css" rel="stylesheet" href="css/add-student-style.css">
</head>
@darbyluv2code
darbyluv2code / student-dropdown-form.html
Created January 4, 2017 15:30
JSP: Drop down forms
<html>
<head><title>Student Registration Form</title></head>
<body>
<form action="student-dropdown-response.jsp">
First name: <input type="text" name="firstName" />