Eclipse設定JDBC連接MySQL資料庫

Java要連接資料庫時,需使用到JDBC-Driver,而Driver可分成四個不同的Type,詳細的內容介紹可以看 簡介 JDBC

連接MySQL資料庫使用Connector/j,下載後解開壓縮後mysql-connector-java-5.1.15-bin.jar就是MySQL的JDBC-Driver了。

底下是在Eclipse使用JDBC-Driver的方法。

一.在Eclipse建立一個專案,增加一個Class

二.設定class name跟package name

三.載入JDBC-Driver

四.程式碼

create drop table,insert update delete等範例。

連接MySQL資料庫方法

五.執行結果

jdbc.jpg


85 comments on “Eclipse設定JDBC連接MySQL資料庫

  1. 妳好!
    我照著這篇教學做了,但出現:
    Exception :java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
    還需要安裝甚麼東西嗎!?

    • 他的意思是你的密碼有問題...
      沒有權限可以使用
      con = DriverManager.getConnection(
      "jdbc:mysql://localhost/test?useUnicode=true&characterEncoding=Big5",
      "root","12345");
      這裡的帳號是root
      密碼是12345
      改成你需要的就可以了

  2. 謝謝這麼快回復!!
    帳號跟密碼是否要在哪邊設定與建檔!?我改別的也是一樣

  3. HI,
    我想請問一下,
    當我執行這程式的時候,等他執行結果非常久,一直沒出現。

    最後才出現這問題

    Exception :com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

    The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
    Exception in thread "main" java.lang.NullPointerException
    at db.jdbcmysql.dropTable(jdbcmysql.java:102)
    at db.jdbcmysql.main(jdbcmysql.java:171)

  4. 不好意思
    我按照步驟ㄧ步一步弄了
    最後執行時發生了錯誤
    DriverClassNotFound :java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    Exception in thread "main" java.lang.NullPointerException
    at db.jdbcmysql.dropTable(jdbcmysql.java:106)
    at db.jdbcmysql.main(jdbcmysql.java:176)
    不知道該怎麼處理><

  5. 您好。首先感謝您的教學
    我也試了您的碼…帳號,密碼都改了
    最後執行出現錯誤
    HTTP Status 404 -
    type Status report

    message

    description The requested resource () is not available.

    想請問,這樣的狀況是連線有問題嗎?

  6. 我也是跑錯誤404

    The requested resource () is not available.

    想請教一下放入文字檔是什麼意思? 怎麼放?

    • 放文字檔 是排除程式complier錯誤
      所以當你放了a.txt檔案
      然後輸入http://你的host:你的port/你的目錄/a.txt
      讀的到 那就是Server設定沒問題
      反之 就是Server設定的問題
      請先利用此方法排除

  7. 您好
    請問是否有重新連接資料表的指令?
    類似重做ResultSet rs = stmt.executeQuery("SELECT * FROM user");的動作
    我目前是再開一個新的ResultSet 去連接,但這太沒效率
    查很久都查不到
    拜托了!

  8. 我利用eclipse 內置的server 執行後丟出
    java.lang.NullPointerException
    db.jdbcmysql.insertProducts(jdbcmysql.java:106)
    com.abc.web.ProductsInsert.doPost(ProductsInsert.java:47)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

    Console:
    DriverClassNotFound :java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

    是不是利用內置的, 不能connect to phpmyadmin呢?

  9. 你好,想要請問一下
    我將public static void main(String[] args)
    {
    jdbcmysql test = new jdbcmysql();
    test.dropTable();
    test.createTable();
    test.insertTable("yku", "12356");
    test.SelectTable();
    }
    中的test.insertTable("yku", "12356"); 改成了我自定義的變數
    (變數另外有寫程式出來)
    執行後也都可以正常寫入資料庫中
    但是卻發現資料會一直覆蓋 只有最後一筆資料可以寫入MySQL中
    想要請問要怎麼讓他自動新增欄位加資料呢?><

  10. 你好,想要請問一下
    我將public static void main(String[] args)
    {
    jdbcmysql test = new jdbcmysql();
    test.dropTable();
    test.createTable();
    test.insertTable("yku", "12356");
    test.SelectTable();
    }
    中的test.insertTable("yku", "12356"); 改成了我自定義的變數
    (變數另外有寫程式出來)
    執行後也都可以正常寫入資料庫中
    但是卻發現資料會一直覆蓋 只有最後一筆資料可以寫入MySQL中
    想要請問大大 要怎麼讓他自動新增欄位加資料呢?><

  11. 大大您好 ,
    先謝謝您先前的解惑,小妹受益良多
    想要再請教一個問題:
    我現在將資料寫入都ok了,但是發現若該筆資料內同時包含數字和字串時
    便無法寫入ˊˋ
    '想要請教一下要怎麼解決呢?><
    萬分感謝!!

    • 不好意思!! 小妹突然打通了任督二脈 已經解決問題了:)
      原來用 toString就可以輕鬆搞定了
      但還是謝謝大大提供了這麼好的環境給我學習!!!^^

  12. 我是Eclipse的初學者 可否請教一下 [連接MySQL資料庫方法]這段Code一直不知道該放在哪??可否說明?或是 這篇文章 有完整專案可以參考???thanks

  13. 您好,

    請問為什麼我在第一台電腦一切運行平穩, 可以連接到driver, mysql...
    但在我的第二台電腦開了程序後, 連接不到driver, mysql?

    我是用 File -> Export -> Runnable JAR file -> Package required libraries into generated JAR

    String url = "jdbc:mysql://localhost:3306/";;
    String db = "UsersDB";
    String driver = "com.mysql.jdbc.Driver";
    String user = "root";
    String pass = "";

    Class.forName(driver);
    con = DriverManager.getConnection(url+db, user, pass);
    Statement st = con.createStatement();
    ResultSet res = st.executeQuery("SELECT * FROM login3");

  14. 想請問一下
    我照這個方法
    可以執行

    但是我想寫一個手機程式來讀取資料庫的東西
    然後我用android建立連線卻失敗

    顯示 DriverClassNotFound:java.long.ClassNotFoundException:com.mysql.jdbc.Driver

    請問原因可能是什麼?

    謝謝!!

    • 我已經解決上面那個問題但是
      卻出現
      Exception :com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

      The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

      請問這可能是什麼問題?

  15. 你好,想請問insertTable裡的

    pst.setString(1, name);
    pst.setString(2, passwd);

    這兩行是什麼意思呢?

    是和剛開始的
    private String insertdbSQL = "insert into User(id,name,passwd) " +
    "select ifNULL(max(id),0)+1,?,? FROM User";
    有關係嗎??

    如果是的話可以請問一下這段SQL ifNULL那裡是什麼意思呢?
    謝謝。

  16. 你好,請問我在eclipse要連到myphpadmin
    也可以用這裡的方法連嗎?
    還是需要其他的動作

    如果這問題太蠢還請見諒 剛接觸不久><

  17. 你好,我照著你的步驟去做,嘗試在我的android app裡面去讀取我的mySQL裡的資料,但是他好像進不去耶!
    因為東西有點多不知道能否用寄信的方式將LOG、程式碼部分寄給您看看?

  18. 可以請問一下 如果我想在資料庫裡放一大串中文字,並加上一個button讓textview一個字一個字依序顯示這串中文字。要如何寫呢?

    因為本人高一,才剛學eclipse,麻煩請給予些指導謝謝:)

  19. 你好 我想請問 為什麼要建立一個新的CLASS ?
    還有我想按下按鈕後 跳到第二頁
    並顯示我查詢的結果
    這樣要怎麼做?
    麻煩給予指導
    感謝

  20. 我是將jdbc改為jtds 確定已有add jar

    Class.forName("net.sourceforge.jtds.jdbc.Driver");
    String dURL="jdbc:jtds:sqlserver://IP:port/databaseName";
    con=DriverManager.getConnection(dURL,"tester","123");

    但結果出現這個
    Exception :java.sql.SQLException: Network error IOException: Connection timed out: connect
    Exception in thread "main" java.lang.NullPointerException
    at sqls.jdbcmysql.dropTable(jdbcmysql.java:100)
    at sqls.jdbcmysql.main(jdbcmysql.java:169)

    • 看錯誤訊息是連線timeout掉了
      請確定您目前這台電腦可以利用ip:port連到資料庫去
      db的port是否firewall有開啟?

  21. 如果是修改某一欄位的資料呢
    一樣SQL語法就好嗎
    函式裡的要怎麼寫還是不需要變更

  22. 你好:我最近是學不到一個禮拜的新手,我在myphpadmin有建立了一個資料庫,要由eclipse執行程式去連接讀檔,需要做甚麼安裝嗎?另外可以私訊mail給我嗎?有語法問題想詢問你,感激不盡.

    • 1.phpMyAdmin是一個連接工具,連接mysql資料庫
      2.eclipse不用經過另一個連接工具去連接mysql,使用JDBC就可以連接mysql了
      3.所以你只要跟著我的範例一步一步做應該就可以了。

  23. 我照你的步驟做之後出現下面的訊息,可以請問一下是哪邊有錯嗎?
    Invalid layout of java.lang.String at value
    #
    # A fatal error has been detected by the Java Runtime Environment:
    #
    # Internal Error (javaClasses.cpp:126), pid=6140, tid=1536
    # fatal error: Invalid layout of preloaded class
    #
    # JRE version: (8.0_25-b18) (build )
    # Java VM: Java HotSpot(TM) Client VM (25.25-b02 mixed mode windows-x86 )
    # Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
    #
    # An error report file with more information is saved as:
    # F:\XXX\XXX\hs_err_pid6140.log
    #
    # If you would like to submit a bug report, please visit:
    # http://bugreport.sun.com/bugreport/crash.jsp
    #

  24. 你好
    像這個
    private String dropdbSQL = "DROP TABLE User ";
    private String createdbSQL = "CREATE TABLE User ......
    我想把User弄成變數
    想換資料庫時只要改變數就可以
    JAVA有能在""中加入變數的嗎

    • 您指的換資料庫是換相同的資料庫系統?還是不同的呢?
      1.如果不同的話,資料庫語法可能不太一樣,應可能要重新設計過
      2.如果想同話,語法是一樣,那您指的變數是?
      以上,謝謝

  25. 我的問題我研究出來了
    我的想法是這樣子的
    變數=某個資料表名稱
    "DROP TABLE 變數 ";
    "CREATE TABLE 變數 ......"
    "UPDATE 變數 SET....."
    我要換別的資料表時候只要改變數就好了
    ---分隔線---
    現在有個問題
    我在本機測試完成要放改用伺服器時
    她顯示
    Exception :java.sql.SQLException: null, message from server: "Host '114-38-34-232.dynamic.hinet.net' is not allowed to connect to this MySQL server"
    這是甚麼意思啊?沒有權限?

  26. 請問為什麼我出現這個錯誤訊息

    Exception in thread "main" java.lang.NoClassDefFoundError: org/aspectj/lang/Signature
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at com.geek.CommectionUtil.open(CommectionUtil.java:24)
    at com.geek.Text.main(Text.java:8)
    Caused by: java.lang.ClassNotFoundException: org.aspectj.lang.Signature
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 4 more

  27. 連線的帳號呢
    前面說的
    1.firewall沒開port
    2.你mysql 帳號並沒有開放你的ip連線
    我都確認過了

    現在這個沒辦法連結的伺服器帳號是管理員給的
    我去試過其他網段的伺服器是可行的

  28. 出現以下訊息,請問該如何排除錯誤?
    Exception in thread "main" java.lang.NullPointerException
    at db.jdbcmysql.dropTable(jdbcmysql.java:102)
    at db.jdbcmysql.main(jdbcmysql.java:171)
    Exception :com.mysql.jdbc.CommunicationsException: Communications link failure

    The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

    • 1.請確認您的mysql jdbc有include進去專案嘛?
      2.連線的帳密及mysql是否access(可以用gui工具先測一下)
      3.確認database及table是否存在
      以上先試看看

  29. 連接MySQL資料庫方法

    try {
    Class.forName("com.mysql.jdbc.Driver");
    //註冊driver
    con = DriverManager.getConnection(
    "jdbc:mysql://localhost/test?useUnicode=true&characterEncoding=Big5",
    "root","12345");
    //取得connection

    //jdbc:mysql://localhost/test?useUnicode=true&characterEncoding=Big5
    //localhost是主機名,test是database名
    //useUnicode=true&characterEncoding=Big5使用的編碼

    }
    catch(ClassNotFoundException e)
    {
    System.out.println("DriverClassNotFound :"+e.toString());
    }//有可能會產生sqlexception
    catch(SQLException x) {
    System.out.println("Exception :"+x.toString());
    }

  30. 用jsp連mysql一直出現錯誤,請問是什麼問題
    SEVERE: Servlet.service() for servlet [jsp] in context with path [/FirstProject] threw exception [javax.servlet.ServletException: java.lang.ExceptionInInitializerError] with root cause
    java.security.AccessControlException: access denied ("java.util.PropertyPermission" "file.encoding" "read")
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:457)
    at java.security.AccessController.checkPermission(AccessController.java:884)
    at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
    at java.lang.SecurityManager.checkPropertyAccess(SecurityManager.java:1294)
    at java.lang.System.getProperty(System.java:717)
    at com.mysql.jdbc.StringUtils.(StringUtils.java:118)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:310)
    at java.sql.DriverManager.getConnection(DriverManager.java:664)
    at java.sql.DriverManager.getConnection(DriverManager.java:247)
    at org.apache.jsp.DBTest_jsp._jspService(DBTest_jsp.java:116)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:431)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:274)
    at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:271)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.Subject.doAsPrivileged(Subject.java:549)
    at org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:306)
    at org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:166)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:285)
    at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:55)
    at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:189)
    at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:185)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:184)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:274)
    at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:271)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.Subject.doAsPrivileged(Subject.java:549)
    at org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:306)
    at org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:246)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:55)
    at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:189)
    at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:185)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:184)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668)
    at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:223)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1517)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1474)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)

  31. 另外是用+el的方式也一直顯示這個錯誤,懇求解答!
    SEVERE: Servlet.service() for servlet [jsp] in context with path [/FirstProject] threw exception [javax.el.ELException: Error reading 'connectedOK' on type com.model.DbBean] with root cause
    java.security.AccessControlException: access denied ("java.util.PropertyPermission" "file.encoding" "read")
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:457)
    at java.security.AccessController.checkPermission(AccessController.java:884)
    at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
    at java.lang.SecurityManager.checkPropertyAccess(SecurityManager.java:1294)
    at java.lang.System.getProperty(System.java:717)
    at com.mysql.jdbc.StringUtils.(StringUtils.java:118)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:310)
    at java.sql.DriverManager.getConnection(DriverManager.java:664)
    at java.sql.DriverManager.getConnection(DriverManager.java:247)
    at com.model.DbBean.isConnectedOK(DbBean.java:26)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at javax.el.BeanELResolver.getValue(BeanELResolver.java:97)
    at org.apache.jasper.el.JasperELResolver.getValue(JasperELResolver.java:110)
    at org.apache.el.parser.AstValue.getValue(AstValue.java:167)
    at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)
    at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:936)
    at org.apache.jsp.DBTest_jsp._jspx_meth_c_005fwhen_005f0(DBTest_jsp.java:284)
    at org.apache.jsp.DBTest_jsp._jspx_meth_c_005fchoose_005f0(DBTest_jsp.java:254)
    at org.apache.jsp.DBTest_jsp._jspService(DBTest_jsp.java:147)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:431)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:274)
    at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:271)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.Subject.doAsPrivileged(Subject.java:549)
    at org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:306)
    at org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:166)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:285)
    at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:55)
    at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:189)
    at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:185)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:184)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:274)
    at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:271)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.Subject.doAsPrivileged(Subject.java:549)
    at org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:306)
    at org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:246)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:55)
    at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:189)
    at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:185)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:184)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668)
    at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:223)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1517)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1474)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)

      • 感謝指導,是安全性的問題已解決,還想請教出現
        java.sql.SQLException: No suitable driver found for jabc:mysql://localhost:3306/sakila是哪邊的問題
        at java.sql.DriverManager.getConnection(DriverManager.java:689)
        at java.sql.DriverManager.getConnection(DriverManager.java:247)
        at com.model.DbBean.isConnectedOK(DbBean.java:26)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at javax.el.BeanELResolver.getValue(BeanELResolver.java:97)
        at org.apache.jasper.el.JasperELResolver.getValue(JasperELResolver.java:110)
        at org.apache.el.parser.AstValue.getValue(AstValue.java:167)
        at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)
        at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:936)
        at org.apache.jsp.DBTest_jsp._jspService(DBTest_jsp.java:146)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:431)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)

2 Pings/Trackbacks 於 "Eclipse設定JDBC連接MySQL資料庫"

發表迴響