Page 769 - 3-2
P. 769

< DbSelect.java >
            import java.sql.*;


            public class DbSelect {


                    static String GetPw()
                    {
                            Connection conn = null;
                            Statement stmt = null;
                            ResultSet res = null;
                            String pw = null;
                            try{
                                    Class.forName("com.mysql.jdbc.Driver").newInstance();
                                    //System.out.println("Driver OK"); //driver  연결 확인
                                    String url = "jdbc:mysql://192.168.0.34/rain"; // 서버 주소 + database    이
            름
                                    String user = "test1"; // 아이디
                                    String passwd = "test1"; // 비번
                                    conn = DriverManager.getConnection(url,user,passwd);
                                    stmt = conn.createStatement();
                                    res = stmt.executeQuery("select * from login"); // login 데이터 불러오기
                                    while(res.next()){
                                            pw = res.getString("pw");
                                    }


                            }
                            catch(Exception e){
                                    System.out.println(e.toString());
                            }finally{
                                    try{
                                            if(res!=null) res.close();
                                            if(stmt!=null) stmt.close();
                                            if(conn!=null) conn.close();
                                    }catch(Exception e){
                                            System.out.println(e.toString());
                                    }
                            }
                            return pw;
                    }
            }




            < GpioExample.java >


            package com.example.user.appclient;


                                                         - 769 -
   764   765   766   767   768   769   770   771   772   773   774