public static final String CHARS = "0123456789ABCDEF";


public static String toHexString(byte[] data) {

StringBuilder sb = new StringBuilder();

for (int i = 0; i < data.length; ++i) {

sb.append(CHARS.charAt((data[i] >> 4) & 0x0F)).append(

CHARS.charAt(data[i] & 0x0F));

}

return sb.toString();

}




'Computer > JAVA' 카테고리의 다른 글

Java 확장 For 문  (0) 2014.08.13
Java HashMap  (0) 2014.08.13
JDBC 출석기능(배열)  (0) 2014.08.11
JDBC SQL Select 기본 예제  (0) 2014.08.11
java 배열 선언  (0) 2014.08.08

for (int i = 0; i < cnt; i++) {

String lecturetime_sql = "select lecture_starttime, lecture_finishtime from lecture where lecture_id = "

+ array2[i][0];

 

rs = st.executeQuery(lecturetime_sql);

while (rs.next()) {

array2[i][1] = rs.getString(1);

array2[i][2] = rs.getString(2);

}

rs.close();

 

System.out.println("Lecture_id = "

+ array2[i][0] + ", StartTime = "

+ array2[i][1] + "("

+ transeMin(array2[i][1]) + ")"

+ ", FinishTime = " + array2[i][2]

+ "(" + transeMin(array2[i][2])

+ ")");

System.out.println(transeMin(nfctime));

 

String att_chk_time = null;

String att_chk_sql = "select start_time from attendance "

+ "where user_id = '"

+ user_id

+ "' and lecture_id = "

+ array2[i][0]

+ " and att_date = to_date('"

+ nfcday + "', 'mm/dd/yyyy')";

 

rs = st.executeQuery(att_chk_sql);

while (rs.next()) {

att_chk_time = rs.getString(1);

}

rs.close();

if (att_chk_time == null) {

if ((transeMin(array2[i][1]) - transeMin(nfctime)) < 10) {

if ((transeMin(nfctime) - transeMin(array2[i][2])) > 10) {

System.out.println("수업종료");

continue;

}

if ((transeMin(array2[i][1]) - transeMin(nfctime)) < 0) {

System.out.println("지각2");

} else {

System.out

.println("0~10분 정상출석입니다.1");

}

 

} else {

System.out.println("수업이 아닙니다.");

continue;

}

} else {

if ((transeMin(nfctime) - transeMin(att_chk_time)) < 10) {

System.out.println("너무 빨리 찍음");

continue;

} else {

if (transeMin(array2[i][2])

- transeMin(nfctime) > 0) {

System.out.println("조퇴3");

} else if (transeMin(nfctime)

- transeMin(array2[i][2]) < 10) {

System.out.println("정상퇴근");

} else {

System.out.println("수업이 아닙니다.");

continue;

}

 

}

 

}

}

'Computer > JAVA' 카테고리의 다른 글

Java HashMap  (0) 2014.08.13
Java 16진수로 변환  (0) 2014.08.12
JDBC SQL Select 기본 예제  (0) 2014.08.11
java 배열 선언  (0) 2014.08.08
JDBC 데이터베이스 연결  (0) 2014.08.08

try {

conn = DBUtil.getConnection();

st = conn.createStatement();

// user_id 조회

String users_sql = "select user_id from users;

rs = st.executeQuery(users_sql);

while (rs.next()) {

user_id = rs.getString(1);

System.out.println("user_id : " + user_id);

}

rs.close();

} catch (SQLException e) {

e.printStackTrace();

} finally {

if (rs != null)

rs.close();

}

'Computer > JAVA' 카테고리의 다른 글

Java HashMap  (0) 2014.08.13
Java 16진수로 변환  (0) 2014.08.12
JDBC 출석기능(배열)  (0) 2014.08.11
java 배열 선언  (0) 2014.08.08
JDBC 데이터베이스 연결  (0) 2014.08.08

출처 : http://xnom.tistory.com/24 






java 배열 선언


  

<!-- google_ad_client = "ca-pub-1832749376699454"; /* up */ google_ad_slot = 

"6330322015"; google_ad_width = 728; google_ad_height = 90; //-->   


※ 일차원 배열 선언





1) 자료형[] 배열명;


2) 자료형 배열명[];





예) short[] sh;


     int aa[];





※ 일차원 배열 초기화 방법





1) 자료형[] 배열명 = { 값1, 값2, 갑3....값n};   (선언과 동시에 초기화)


2) 배열명 = new 자료형[개수];   (선언과 별개로 초기화 가능)


3) 배열명 = new 자료형[]{ 값1, 값2, 갑3....값n};   (선언과 별개로 초기화 가능)





예) char[] ch = {'a', 'b', 'c'};





     int[] a;


     a = new int[3];





     float b[];


     b = new float[]{1.2f, 2.3f, 3.4f};





예 2)



   int[] arr = new int[2];


   int arr[] = new int[2];


   int[] arr = { 0, 1 };


   int arr[] = { 0, 1};






※ java에서 배열의 선언과 초기화 방법의 경우





자료형 배열명[] or 자료형[] 배열명 : 1. 바로 초기화 값이 뒤 이어 온다.


                                                            (={값, 값, 값};)



                                                        2. 바로 new 자료형[개수] 형태로 

배열의 크기를 정한다.


                                                           (=new int[5];)


                                                             - 이때 new 자료형[]{} 

형태로 초기화 선언이 가능하다.


                                                                 (=new 

int[]{값1,값2,값3};)


                                                        3. 선언 이후 나중에 배열이름 = new 

자료형[]{} 형태로 초기화가 가능하다.


                                                            (a=new 

int[]{1,2,3,5};)


                                             4. 선언 이후 나중에 배열이름 = new 자료형[개수] 형태로 

배열의 크기를 정한다. 


                                                            (a=new int[5];)


                                                         








※ 배열의 개수 구하기 (.length)



int a[] = {1,2,3,4,....,n};


int n = a.length;   //배열의 개수를 구해준다.





단, 다차원 배열의 경우는 차이가 난다.


예) int a[3][2]={{1,2},{2,3},{3,4}};


     int x=a.length


     일 경우 x는 a[3]의 개수{{}->1개, {}->2개,->3개}; 를 읽어 3을 표기한다.


     정확히는 메모리 상에서 a[0],a[1],a[2]의 주소값을 읽어와 갯수를 나타낸다.


     (a[0]은 각각 a[0][0],a[0][1]의 주소값을 가진다.)


    int x=a[0].length


     일 경우 x는 a[0]의 값 1,2을 읽어 갯수 2를 나타낸다.











※ 다차원 배열의 선언





1) 자료형[][[] 배열명;


2) 자료형[] 배열명[];


3) 자료형 배열명[][];





예) int[][] aa;


     int[] aa[];


     int aa[][];


주의 - int[] a, b[] - a는 1차원 배열, b는 2차원 배열을 뜻한다.





※ 다차원 배열의 초기화





1) 자료형[][] 배열명 = {{값1,값2},{값1,값2}.....{값a,값b}};


2) 배열명 = new 자료형[][]{{값1,값2},{값1,값2}.....{값a,값b}};


3) 배열명 = new 자료형[개수][개수];


4) 배열명 = new 자료형[개수][];





예) int[][] a = {{1,2},{1,3}};


     


int[][] a;


a=new int[][]{{1,2},{1,3}};


a=new int[3][2];


      a=new int[3][];








※ 다차원 배열의 초기화 - 각기 다른 배열 길이를 갖는 선언








char[][] = new char[3][];


3개의 배열은 각기 다른 배열을 가질 수 있다.





char[0]=new char[7];


char[1]=new char[1];


char[2]=new char[4];

'Computer > JAVA' 카테고리의 다른 글

Java HashMap  (0) 2014.08.13
Java 16진수로 변환  (0) 2014.08.12
JDBC 출석기능(배열)  (0) 2014.08.11
JDBC SQL Select 기본 예제  (0) 2014.08.11
JDBC 데이터베이스 연결  (0) 2014.08.08

DBUtil.java

public class DButil {


public static Connection getConnection() {

Connection conn = null;

Properties p = new Properties();


try {

p.load(new FileReader(

"src/com/ninethirty/hellolecture/nfc/dbinfo.properties"));

} catch (FileNotFoundException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

String driver = p.getProperty("driver");

try {

Class.forName(driver);

} catch (ClassNotFoundException e) {

e.printStackTrace();

}

try {

conn = DriverManager.getConnection(p.getProperty("url"),

p.getProperty("userid"), p.getProperty("password"));


System.out.println("DB Connection");

} catch (SQLException e) {

e.printStackTrace();

}


return conn;

}


public static void close(Connection conn, Statement st) {

try {

if (conn != null)

conn.close();

if (st != null)

st.close();


} catch (SQLException e) {

e.printStackTrace();

}

}


}




dbinfo.properties

driver=oracle.jdbc.OracleDriver
url=jdbc:oracle:thin:@localhost:1521:xe
userid=hr
password=hr




사용하기
try {
conn = DBUtil.getConnection();
st = conn.createStatement();
String users_sql = "select * from tablename";
rs = st.executeQuery(users_sql);
while (rs.next()) {
user_id = rs.getString(1);
user_name = rs.getString(2);
}
rs.close();
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (rs != null)
rs.close();
}


'Computer > JAVA' 카테고리의 다른 글

Java HashMap  (0) 2014.08.13
Java 16진수로 변환  (0) 2014.08.12
JDBC 출석기능(배열)  (0) 2014.08.11
JDBC SQL Select 기본 예제  (0) 2014.08.11
java 배열 선언  (0) 2014.08.08

+ Recent posts