publicBDao(){ try{ Contextinit=newInitialContext(); Contextenv= (Context)init.lookup("java:comp/env"); DataSourceds= (DataSource)env.lookup("jdbc/mysql"); connection = ds.getConnection(); System.out.println("db connection success!!"); } catch (NamingException e) { e.printStackTrace(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } // 각 method 에서 connection, ps, rs 를 close() 해주는 것을 잊지 말자
주의사항
mysql connector는 소스쪽과 서버쪽 폴더 동시에 적용시켜야한다.(복사)
위와 같이 했음에도 아래와 같이 에러가 나는 경우
심각: Servlet.service() for servlet [com.javalec.ex.frontcontroller.BFrontContrller] in context with path [/first_test] threw exception [Servlet execution threw an exception] with root cause
위에설치한 4개의jar파일중 버전이 맞지 않아서 생기는 에러(ex. mysql-connector-java-5.1.44-bin.jar이 낮아서 생기는 에러였음)
gpg: directory '/root/.gnupg' created gpg: new configuration file '/root/.gnupg/gpg.conf' created gpg: WARNING: options in'/root/.gnupg/gpg.conf' are not yet active during this run gpg: keyring '/root/.gnupg/secring.gpg' created gpg: keyring '/root/.gnupg/pubring.gpg' created gpg: "key" not a key ID: skipping gpg: requesting key 11A06851 from hkp server pgpkeys.mit.edu sudo gpg --armgpg: /root/.gnupg/trustdb.gpg: trustdb created gpg: key 11A06851: public key "Mateusz Łukasik <mati75@linuxmint.pl>" imported gpg: Total number processed: 1 gpg: imported: 1 (RSA: 1) $ sudo gpg --armor --export CCD91D6111A06851 | sudo apt-key add -