2012-08-31 3 views
0

Java에서 MySQL을 처음 사용하려고합니다. 나는이 코드 tutorial을 따라 왔고 코드를 작성할 수 있었지만 아직 잘못되고있는 부분을 이해하지 못했습니다. 다음과 같은 메시지가 나타납니다.Java에서 MySQL에 액세스 할 때의 문제

terminated docsconnectionpropshelper java application 

디버그 중지 지점이있는 주 클래스에 도달하지도 않습니다.

내 코드는 다음과 같습니다

public class CDaoAccess implements IDaoAccess { 

    public static Connection connect = null; 
    private Statement statement = null; 
    private PreparedStatement preparedStatement = null; 
    private ResultSet resultSet = null; 

    @Override 
    public void connectDatabase(String _database) throws Exception { 

    // This will load the MySQL driver, each DB has its own driver 
    Class.forName("com.mysql.jdbc.Driver");  
    connect = DriverManager.getConnection(
     "jdbc:mysql://localhost:3306/DAH-MS-DB","root","root"); 

    statement = connect.createStatement();  
    resultSet =statement.executeQuery("select * from DAH-MS-DB.Patient");  
    close(); 
    } 

    @Override 
    public void close() throws SQLException { 
    // TODO Auto-generated method stub 
    try { 
     if (resultSet != null) { 
     resultSet.close(); 
     } 

     if (statement != null) { 
     statement.close(); 
     } 

     if (connect != null) { 
     connect.close(); 
     } 
    } catch (Exception e) { 

    } 
    } 
} 

LOG :

<ConnectionProperties> 
<PropertyCategory name="Connection/Authentication"> 
    <Property name="user" required="No" default="" sortOrder="-2147483647" since="all versions"> 
    The user to connect as 
    </Property> 
    <Property name="password" required="No" default="" sortOrder="-2147483646" since="all versions"> 
    The password to use when connecting 
    </Property> 
    <Property name="socketFactory" required="No" default="com.mysql.jdbc.StandardSocketFactory" sortOrder="4" since="3.0.3"> 
    The name of the class that the driver should use for creating socket connections to the server. This class must implement the interface 'com.mysql.jdbc.SocketFactory' and have public no-args constructor. 
    </Property> 
    <Property name="connectTimeout" required="No" default="0" sortOrder="9" since="3.0.1"> 
    Timeout for socket connect (in milliseconds), with 0 being no timeout. Only works on JDK-1.4 or newer. Defaults to '0'. 
    </Property> 
    <Property name="socketTimeout" required="No" default="0" sortOrder="10" since="3.0.1"> 
    Timeout on network socket operations (0, the default means no timeout). 
    </Property> 
    <Property name="connectionLifecycleInterceptors" required="No" default="" sortOrder="2147483647" since="5.1.4"> 
    A comma-delimited list of classes that implement "com.mysql.jdbc.ConnectionLifecycleInterceptor" that should notified of connection lifecycle events (creation, destruction, commit, rollback, setCatalog and setAutoCommit) and potentially alter the execution of these commands. ConnectionLifecycleInterceptors are "stackable", more than one interceptor may be specified via the configuration property as a comma-delimited list, with the interceptors executed in order from left to right. 
    </Property> 
    <Property name="useConfigs" required="No" default="" sortOrder="2147483647" since="3.1.5"> 
    Load the comma-delimited list of configuration properties before parsing the URL or applying user-specified properties. These configurations are explained in the 'Configurations' of the documentation. 
    </Property> 
    <Property name="authenticationPlugins" required="No" default="" sortOrder="alpha" since="5.1.19"> 
    Comma-delimited list of classes that implement com.mysql.jdbc.AuthenticationPlugin and which will be used for authentication unless disabled by "disabledAuthenticationPlugins" property. 
    </Property> 
    <Property name="defaultAuthenticationPlugin" required="No" default="com.mysql.jdbc.authentication.MysqlNativePasswordPlugin" sortOrder="alpha" since="5.1.19"> 
    Name of a class implementing com.mysql.jdbc.AuthenticationPlugin which will be used as the default authentication plugin (see below). It is an error to use a class which is not listed in "authenticationPlugins" nor it is one of the built-in plugins. It is an error to set as default a plugin which was disabled with "disabledAuthenticationPlugins" property. It is an error to set this value to null or the empty string (i.e. there must be at least a valid default authentication plugin specified for the connection, meeting all constraints listed above). 
    </Property> 
    <Property name="disabledAuthenticationPlugins" required="No" default="" sortOrder="alpha" since="5.1.19"> 
    Comma-delimited list of classes implementing com.mysql.jdbc.AuthenticationPlugin or mechanisms, i.e. "mysql_native_password". The authentication plugins or mechanisms listed will not be used for authentication which will fail if it requires one of them. It is an error to disable the default authentication plugin (either the one named by "defaultAuthenticationPlugin" property or the hard-coded one if "defaultAuthenticationPlugin" propery is not set). 
    </Property> 
    <Property name="interactiveClient" required="No" default="false" sortOrder="alpha" since="3.1.0"> 
    Set the CLIENT_INTERACTIVE flag, which tells MySQL to timeout connections based on INTERACTIVE_TIMEOUT instead of WAIT_TIMEOUT 
    </Property> 
    <Property name="localSocketAddress" required="No" default="" sortOrder="alpha" since="5.0.5"> 
    Hostname or IP address given to explicitly configure the interface that the driver will bind the client side of the TCP/IP connection to when connecting. 
    </Property> 
    <Property name="propertiesTransform" required="No" default="" sortOrder="alpha" since="3.1.4"> 
    An implementation of com.mysql.jdbc.ConnectionPropertiesTransform that the driver will use to modify URL properties passed to the driver before attempting a connection 
    </Property> 
    <Property name="useCompression" required="No" default="false" sortOrder="alpha" since="3.0.17"> 
    Use zlib compression when communicating with the server (true/false)? Defaults to 'false'. 
    </Property> 
</PropertyCategory> 
<PropertyCategory name="Networking"> 
    <Property name="maxAllowedPacket" required="No" default="-1" sortOrder="alpha" since="5.1.8"> 
    Maximum allowed packet size to send to server. If not set, the value of system variable 'max_allowed_packet' will be used to initialize this upon connecting. This value will not take effect if set larger than the value of 'max_allowed_packet'. 
    </Property> 
    <Property name="tcpKeepAlive" required="No" default="true" sortOrder="alpha" since="5.0.7"> 
    If connecting using TCP/IP, should the driver set SO_KEEPALIVE? 
    </Property> 
    <Property name="tcpNoDelay" required="No" default="true" sortOrder="alpha" since="5.0.7"> 
    If connecting using TCP/IP, should the driver set SO_TCP_NODELAY (disabling the Nagle Algorithm)? 
    </Property> 
    <Property name="tcpRcvBuf" required="No" default="0" sortOrder="alpha" since="5.0.7"> 
    If connecting using TCP/IP, should the driver set SO_RCV_BUF to the given value? The default value of '0', means use the platform default value for this property) 
    </Property> 
    <Property name="tcpSndBuf" required="No" default="0" sortOrder="alpha" since="5.0.7"> 
    If connecting using TCP/IP, should the driver set SO_SND_BUF to the given value? The default value of '0', means use the platform default value for this property) 
    </Property> 
    <Property name="tcpTrafficClass" required="No" default="0" sortOrder="alpha" since="5.0.7"> 
    If connecting using TCP/IP, should the driver set traffic class or type-of-service fields ?See the documentation for java.net.Socket.setTrafficClass() for more information. 
    </Property> 
</PropertyCategory> 
<PropertyCategory name="High Availability and Clustering"> 
    <Property name="autoReconnect" required="No" default="false" sortOrder="0" since="1.1"> 
    Should the driver try to re-establish stale and/or dead connections? If enabled the driver will throw an exception for a queries issued on a stale or dead connection, which belong to the current transaction, but will attempt reconnect before the next query issued on the connection in a new transaction. The use of this feature is not recommended, because it has side effects related to session state and data consistency when applications don't handle SQLExceptions properly, and is only designed to be used when you are unable to configure your application to handle SQLExceptions resulting from dead and stale connections properly. Alternatively, as a last option, investigate setting the MySQL server variable "wait_timeout" to a high value, rather than the default of 8 hours. 
    </Property> 
    <Property name="autoReconnectForPools" required="No" default="false" sortOrder="1" since="3.1.3"> 
    Use a reconnection strategy appropriate for connection pools (defaults to 'false') 
    </Property> 
    <Property name="failOverReadOnly" required="No" default="true" sortOrder="2" since="3.0.12"> 
    When failing over in autoReconnect mode, should the connection be set to 'read-only'? 
    </Property> 
    <Property name="maxReconnects" required="No" default="3" sortOrder="4" since="1.1"> 
    Maximum number of reconnects to attempt if autoReconnect is true, default is '3'. 
    </Property> 
    <Property name="reconnectAtTxEnd" required="No" default="false" sortOrder="4" since="3.0.10"> 
    If autoReconnect is set to true, should the driver attempt reconnections at the end of every transaction? 
    </Property> 
    <Property name="retriesAllDown" required="No" default="120" sortOrder="4" since="5.1.6"> 
    When using loadbalancing, the number of times the driver should cycle through available hosts, attempting to connect. Between cycles, the driver will pause for 250ms if no servers are available. 
    </Property> 
    <Property name="initialTimeout" required="No" default="2" sortOrder="5" since="1.1"> 
    If autoReconnect is enabled, the initial time to wait between re-connect attempts (in seconds, defaults to '2'). 
    </Property> 
    <Property name="roundRobinLoadBalance" required="No" default="false" sortOrder="5" since="3.1.2"> 
    When autoReconnect is enabled, and failoverReadonly is false, should we pick hosts to connect to on a round-robin basis? 
    </Property> 
    <Property name="queriesBeforeRetryMaster" required="No" default="50" sortOrder="7" since="3.0.2"> 
    Number of queries to issue before falling back to master when failed over (when using multi-host failover). Whichever condition is met first, 'queriesBeforeRetryMaster' or 'secondsBeforeRetryMaster' will cause an attempt to be made to reconnect to the master. Defaults to 50. 
    </Property> 
    <Property name="secondsBeforeRetryMaster" required="No" default="30" sortOrder="8" since="3.0.2"> 
    How long should the driver wait, when failed over, before attempting 
    </Property> 
    <Property name="selfDestructOnPingMaxOperations" required="No" default="0" sortOrder="2147483647" since="5.1.6"> 
    =If set to a non-zero value, the driver will report close the connection and report failure when Connection.ping() or Connection.isValid(int) is called if the connnection's count of commands sent to the server exceeds this value. 
    </Property> 
    <Property name="selfDestructOnPingSecondsLifetime" required="No" default="0" sortOrder="2147483647" since="5.1.6"> 
    If set to a non-zero value, the driver will report close the connection and report failure when Connection.ping() or Connection.isValid(int) is called if the connnection's lifetime exceeds this value. 
    </Property> 
    <Property name="resourceId" required="No" default="" sortOrder="alpha" since="5.0.1"> 
    A globally unique name that identifies the resource that this datasource or connection is connected to, used for XAResource.isSameRM() when the driver can't determine this value based on hostnames used in the URL 
    </Property> 
</PropertyCategory> 
<PropertyCategory name="Security"> 
    <Property name="allowMultiQueries" required="No" default="false" sortOrder="1" since="3.1.1"> 
    Allow the use of ';' to delimit multiple queries during one statement (true/false), defaults to 'false', and does not affect the addBatch() and executeBatch() methods, which instead rely on rewriteBatchStatements. 
    </Property> 
    <Property name="useSSL" required="No" default="false" sortOrder="2" since="3.0.2"> 
    Use SSL when communicating with the server (true/false), defaults to 'false' 
    </Property> 
    <Property name="requireSSL" required="No" default="false" sortOrder="3" since="3.1.0"> 
    Require SSL connection if useSSL=true? (defaults to 'false'). 
    </Property> 
    <Property name="verifyServerCertificate" required="No" default="true" sortOrder="4" since="5.1.6"> 
    If "useSSL" is set to "true", should the driver verify the server's certificate? When using this feature, the keystore parameters should be specified by the "clientCertificateKeyStore*" properties, rather than system properties. 
    </Property> 
    <Property name="clientCertificateKeyStoreUrl" required="No" default="" sortOrder="5" since="5.1.0"> 
    URL to the client certificate KeyStore (if not specified, use defaults) 
    </Property> 
    <Property name="clientCertificateKeyStoreType" required="No" default="JKS" sortOrder="6" since="5.1.0"> 
    KeyStore type for client certificates (NULL or empty means use the default, which is "JKS". Standard keystore types supported by the JVM are "JKS" and "PKCS12", your environment may have more available depending on what security products are installed and available to the JVM. 
    </Property> 
    <Property name="clientCertificateKeyStorePassword" required="No" default="" sortOrder="7" since="5.1.0"> 
    Password for the client certificates KeyStore 
    </Property> 
    <Property name="trustCertificateKeyStoreUrl" required="No" default="" sortOrder="8" since="5.1.0"> 
    URL to the trusted root certificate KeyStore (if not specified, use defaults) 
    </Property> 
    <Property name="trustCertificateKeyStoreType" required="No" default="JKS" sortOrder="9" since="5.1.0"> 
    KeyStore type for trusted root certificates (NULL or empty means use the default, which is "JKS". Standard keystore types supported by the JVM are "JKS" and "PKCS12", your environment may have more available depending on what security products are installed and available to the JVM. 
    </Property> 
    <Property name="trustCertificateKeyStorePassword" required="No" default="" sortOrder="10" since="5.1.0"> 
    Password for the trusted root certificates KeyStore 
    </Property> 
    <Property name="allowLoadLocalInfile" required="No" default="true" sortOrder="2147483647" since="3.0.3"> 
    Should the driver allow use of 'LOAD DATA LOCAL INFILE...' (defaults to 'true'). 
    </Property> 
    <Property name="allowUrlInLocalInfile" required="No" default="false" sortOrder="2147483647" since="3.1.4"> 
    Should the driver allow URLs in 'LOAD DATA LOCAL INFILE' statements? 
    </Property> 
    <Property name="paranoid" required="No" default="false" sortOrder="alpha" since="3.0.1"> 
    Take measures to prevent exposure sensitive information in error messages and clear data structures holding sensitive data when possible? (defaults to 'false') 
    </Property> 
    <Property name="passwordCharacterEncoding" required="No" default="" sortOrder="alpha" since="5.1.7"> 
    What character encoding is used for passwords? Leaving this set to the default value (null), uses the platform character set, which works for ISO8859_1 (i.e. "latin1") passwords. For passwords in other character encodings, the encoding will have to be specified with this property, as it's not possible for the driver to auto-detect this. 
    </Property> 
</PropertyCategory> 
<PropertyCategory name="Performance Extensions"> 
    <Property name="callableStmtCacheSize" required="No" default="100" sortOrder="5" since="3.1.2"> 
    If 'cacheCallableStmts' is enabled, how many callable statements should be cached? 
    </Property> 
    <Property name="metadataCacheSize" required="No" default="50" sortOrder="5" since="3.1.1"> 
    The number of queries to cache ResultSetMetadata for if cacheResultSetMetaData is set to 'true' (default 50) 
    </Property> 
    <Property name="useLocalSessionState" required="No" default="false" sortOrder="5" since="3.1.7"> 
    Should the driver refer to the internal values of autocommit and transaction isolation that are set by Connection.setAutoCommit() and Connection.setTransactionIsolation() and transaction state as maintained by the protocol, rather than querying the database or blindly sending commands to the database for commit() or rollback() method calls? 
    </Property> 
    <Property name="useLocalTransactionState" required="No" default="false" sortOrder="6" since="5.1.7"> 
    Should the driver use the in-transaction state provided by the MySQL protocol to determine if a commit() or rollback() should actually be sent to the database? 
    </Property> 
    <Property name="prepStmtCacheSize" required="No" default="25" sortOrder="10" since="3.0.10"> 
    If prepared statement caching is enabled, how many prepared statements should be cached? 
    </Property> 
    <Property name="prepStmtCacheSqlLimit" required="No" default="256" sortOrder="11" since="3.0.10"> 
    If prepared statement caching is enabled, what's the largest SQL the driver will cache the parsing for? 
    </Property> 
    <Property name="parseInfoCacheFactory" required="No" default="com.mysql.jdbc.PerConnectionLRUFactory" sortOrder="12" since="5.1.1"> 
    Name of a class implementing com.mysql.jdbc.CacheAdapterFactory, which will be used to create caches for the parsed representation of client-side prepared statements. 
    </Property> 
    <Property name="alwaysSendSetIsolation" required="No" default="true" sortOrder="2147483647" since="3.1.7"> 
    Should the driver always communicate with the database when Connection.setTransactionIsolation() is called? If set to false, the driver will only communicate with the database when the requested transaction isolation is different than the whichever is newer, the last value that was set via Connection.setTransactionIsolation(), or the value that was read from the server when the connection was established. Note that useLocalSessionState=true will force the same behavior as alwaysSendSetIsolation=false, regardless of how alwaysSendSetIsolation is set. 
    </Property> 
    <Property name="maintainTimeStats" required="No" default="true" sortOrder="2147483647" since="3.1.9"> 
    Should the driver maintain various internal timers to enable idle time calculations as well as more verbose error messages when the connection to the server fails? Setting this property to false removes at least two calls to System.getCurrentTimeMillis() per query. 
    </Property> 
    <Property name="useCursorFetch" required="No" default="false" sortOrder="2147483647" since="5.0.0"> 
    If connected to MySQL > 5.0.2, and setFetchSize() > 0 on a statement, should that statement use cursor-based fetching to retrieve rows? 
    </Property> 
    <Property name="blobSendChunkSize" required="No" default="1048576" sortOrder="alpha" since="3.1.9"> 
    Chunk to use when sending BLOB/CLOBs via ServerPreparedStatements 
    </Property> 
    <Property name="cacheCallableStmts" required="No" default="false" sortOrder="alpha" since="3.1.2"> 
    Should the driver cache the parsing stage of CallableStatements 
    </Property> 
    <Property name="cachePrepStmts" required="No" default="false" sortOrder="alpha" since="3.0.10"> 
    Should the driver cache the parsing stage of PreparedStatements of client-side prepared statements, the "check" for suitability of server-side prepared and server-side prepared statements themselves? 
    </Property> 
    <Property name="cacheResultSetMetadata" required="No" default="false" sortOrder="alpha" since="3.1.1"> 
    Should the driver cache ResultSetMetaData for Statements and PreparedStatements? (Req. JDK-1.4+, true/false, default 'false') 
    </Property> 
    <Property name="cacheServerConfiguration" required="No" default="false" sortOrder="alpha" since="3.1.5"> 
    Should the driver cache the results of 'SHOW VARIABLES' and 'SHOW COLLATION' on a per-URL basis? 
    </Property> 
    <Property name="defaultFetchSize" required="No" default="0" sortOrder="alpha" since="3.1.9"> 
    The driver will call setFetchSize(n) with this value on all newly-created Statements 
+0

자습서에서 얼마나 멀리 있었는지 및/또는 일어난 일에서 무엇을하고 있었는지 말할 수 있습니까? 네가받은 유일한 메시지가 당신이 인용 한 메시지인가? 예외는 없었습니까? 'static void Main (string [] args)'-method의 첫번째 줄에 디버그 포인트가 있고 그걸 명중하지 않았다는 말입니까? –

+0

예외는 어디에서 발생합니까? 로그 파일을 사용할 수 있습니까? – home

+0

@AskeB. 그것은 정적 공백 메인 (문자열 [] args)에서 전혀 – MGD

답변

0

MSG 및 프로그램 나던도 디버그 정지 지점이 위치한 메인 클래스로 제공됩니다.

이렇게하면 달리 실행하는 방법에 문제가있는 것입니다. Maven을 사용하여 빌드를 수행하는 경우 NetBeans가 기본적으로 Maven poms를 프로젝트 파일 형식으로 지원하므로 NetBeans에서이 프로젝트를 쉽게 열 수 있습니다. 그런 식으로 코드를 실행하면 NetBeans로 전환 할 수 있습니다. 이 예제와

+0

감사의 조언하지만 해결책을 얻는 데 시간이 걸릴 것입니다. (.. 지금 당장 일식을 계속 사용하고 싶습니다. – MGD

0

점검 :

package stack; 

import java.sql.Connection; 
import java.sql.DriverManager; 
import java.sql.ResultSet; 
import java.sql.SQLException; 
import java.sql.Statement; 


public class Test { 
    public void connectDatabase(){ 
     Connection conn = null; 
     Statement st = null; 
     ResultSet rs = null; 
     try{ 
      Class.forName("com.mysql.jdbc.Driver"); 
      conn = DriverManager.getConnection(
       "jdbc:mysql://localhost:3306/DAH-MS-DB","root","root"); 
      st = conn.createStatement(); 
      rs = st.executeQuery("select * from DAH-MS-DB.Patient"); 
      while(rs.next()){ 
       //Use datas 
      } 
     }catch(Exception e){ 
      e.printStackTrace(); 
     }finally{ 
      try { 
       rs.close(); 
      } catch (SQLException e) { 
       e.printStackTrace(); 
      } 
      try { 
       st.close(); 
      } catch (SQLException e) { 
       e.printStackTrace(); 
      } 
      try { 
       conn.close(); 
      } catch (SQLException e) { 
       e.printStackTrace(); 
      } 
     } 
    } 
} 
+0

도움을 주셔서 감사합니다. 같은 문제가 계속 발생했습니다. – MGD

0

흠 정말 정확히 무슨 일이 있었는지 몰라요, 나는 "새 자바 프로젝트"와 현재 작업에 튜토리얼에서 동일한 단계를 따랐다.

2

응용 프로그램으로 JDBC를 통해 MySQL에 연결을 시도하는 java 파일을 실행하십시오. 자바 파일

2)에

1) 마우스 오른쪽 단추로 클릭

3) 선택 자바 응용 프로그램으로 실행에 이동합니다.

그것은 나를 위해 문제를 해결했습니다.

+0

답변에서 OP가 이미 자신의 문제를 해결했음을 알 수 있습니다.1 년 된 질문에 부딪 칠 필요가 없습니다. –

0

잠시 전에이 문제가있었습니다. 내 문제는 이클립스와 함께, 그것은 mysql.jar 그것을 사용했다 주했다. 프로젝트를 마우스 오른쪽 버튼으로 클릭하고 다른 이름으로 실행을 선택하고 구성을 실행하십시오. enter image description here 전화를 걸고있는 주 수업이 메인인지 확인하십시오.

관련 문제