java.sql.sqldataexception: cannot determine value type from string

时间: 2023-04-26 18:01:23 浏览: 405
java.sql.sqldataexception: 无法从字符串确定值类型。 这个错误通常是由于在将字符串转换为数据库中的值时出现问题。可能是因为字符串格式不正确,或者数据库中的列类型与字符串类型不匹配。需要检查代码中的数据类型和格式,并确保它们与数据库中的列类型匹配。
相关问题

java.sql.SQLDataException: Cannot determine value type from string '小军'

这个错误是由于在使用 JDBC 进行数据库操作时,尝试将一个无法识别的字符串转换成对应的数据类型时引起的。在这个例子中,你尝试将字符串 '小军' 转换成某个数据类型,但是 JDBC 无法确定该字符串应该被转换成什么类型。 为了解决这个问题,你需要检查你的代码,并查找可能导致这个问题的原因。通常,这个问题是由于将一个字符串插入到一个不适合的数据类型的列中引起的。例如,如果一个字符串被插入到一个数字列中,就会导致这个错误。 你可以尝试使用一些调试工具来定位这个问题,或者在代码中添加一些日志来帮助你找到问题的根源。另外,你也可以检查数据库中的数据类型是否与你的代码中使用的数据类型相匹配。

Caused by: java.sql.SQLDataException: Cannot determine value type from string '男'

这个错误通常是由于 JDBC 驱动程序尝试将字符串 '男' 转换为数据库中的某个数据类型时失败了。这可能是因为数据库中的列类型与您传递给 JDBC 驱动程序的值类型不匹配。 您可以检查以下事项: 1. 确认数据库表中列的数据类型与您将要插入的值的数据类型相匹配。 2. 检查您使用的 JDBC 驱动程序是否支持该数据类型。如果不支持,则可能需要使用不同的数据类型或更新 JDBC 驱动程序版本。 3. 确认您的代码没有将值类型错误地传递给 JDBC 驱动程序。您可以使用调试器或打印语句来检查传递给 JDBC 驱动程序的值。 希望这些提示能够帮助您解决问题。
阅读全文

相关推荐

我有一个问题 这是我的代码package hometel; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; /**jdbc快速入门demo*/ public class JDBCDemo2resultset { public static void main(String[] args) throws Exception { // Class.forName("com.mysql.jdbc.Driver"); //注册驱动 String url ="jdbc:mysql:///hotel?useSSL=false&serverTimezone=Asia/Shanghai"; String username = "root"; String password = "Lqh2005320"; //获取链接 Connection conn = DriverManager.getConnection(url,username,password); String sql = "select * from shop"; Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(sql); while(rs.next()){ int id = rs.getInt(1); String name = rs.getString(2); int price = rs.getInt(3); System.out.println("id:"+id+" name:"+name+" price:"+price); System.out.println("-----"); } rs.close(); stmt.close(); conn.close(); } }出现以下问题xception in thread "main" java.sql.SQLDataException: Cannot determine value type from string '大学城' at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:112) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:95) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:87) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:61) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:71) at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:96) at com.mysql.cj.jdbc.result.ResultSetImpl.getInt(ResultSetImpl.java:827) at hometel.JDBCDemo2resultset.main(JDBCDemo2resultset.java:23) Caused by: com.mysql.cj.exceptions.DataConversionException: Cannot determine value type from string '大学城' at com.mysql.cj.result.StringConverter.createFromBytes(StringConverter.java:127) at com.mysql.cj.protocol.a.MysqlTextValueDecoder.decodeByteArray(MysqlTextValueDecoder.java:238) at com.mysql.cj.protocol.result.AbstractResultsetRow.decodeAndCreateReturnValue(AbstractResultsetRow.java:129) at com.mysql.cj.protocol.result.AbstractResultsetRow.getValueFromBytes(AbstractResultsetRow.java:233) at com.mysql.cj.protocol.a.result.ByteArrayRow.getValue(ByteArrayRow.java:91) at com.mysql.cj.jdbc.result.ResultSetImpl.getNonStringValueFromRow(ResultSetImpl.java:628) ... 2 more 进程已结束,退出代码为 1 怎么办

public class Test4 { public static void main(String[] args){ Connection connection = null; Statement statement = null; ResultSet resultSet = null; String dirver = "com.mysql.cj.jdbc.Driver"; try { Class.forName(dirver); String url = "jdbc:mysql://localhost:3307/epet";// 数据库地址 String user = "root";// 数据库用户名 String password = "123456";// 数据库密码 connection = DriverManager.getConnection(url,user,password); if(connection != null){ System.out.println("链接成功!!");// 建议改为"连接成功" } // 3. 创建Statement对象(用于执行SQL语句) statement = connection.createStatement(); resultSet = statement.executeQuery("select*from pet"); while (resultSet.next()){ System.out.print(resultSet.getInt(1)+"\t"); System.out.print(resultSet.getInt(2)+"\t"); System.out.print(resultSet.getInt("health")+"\t"); System.out.println(); } //System.out.println(result == 1 ? "执行成功" : "执行失败"); } catch (SQLException e) { System.out.println("数据库链接失败"); e.printStackTrace(); }catch (ClassNotFoundException e){ e.printStackTrace(); }finally { // 7. 资源释放(按打开顺序反向关闭) if(resultSet != null){ try { resultSet.close(); } catch (SQLException e) { e.printStackTrace(); } } if(statement != null){ try { statement.close(); } catch (SQLException e) { e.printStackTrace(); } } if(connection != null){ try { connection.close(); }catch (SQLException e){ e.printStackTrace(); } } } } } 链接成功!! 1 数据库链接失败 java.sql.SQLDataException: Cannot determine value type from string '小黑' at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:114) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:73) at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:96) at com.mysql.cj.jdbc.result.ResultSetImpl.getObject(ResultSetImpl.java:1431) at com.mysql.cj.jdbc.result.ResultSetImpl.getInt(ResultSetImpl.java:830) at JDBC.Test4.main(Test4.java:25) Caused by: com.mysql.cj.exceptions.DataConversionException: Cannot determine value type from string '小黑' at com.mysql.cj.result.AbstractNumericValueFactory.createFromBytes(AbstractNumericValueFactory.java:65) at com.mysql.cj.protocol.a.MysqlTextValueDecoder.decodeByteArray(MysqlTextValueDecoder.java:143) at com.mysql.cj.protocol.result.AbstractResultsetRow.decodeAndCreateReturnValue(AbstractResultsetRow.java:135) at com.mysql.cj.protocol.result.AbstractResultsetRow.getValueFromBytes(AbstractResultsetRow.java:243) at com.mysql.cj.protocol.a.result.ByteArrayRow.getValue(ByteArrayRow.java:91) at com.mysql.cj.jdbc.result.ResultSetImpl.getObject(ResultSetImpl.java:1324) ... 2 more

/* * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.springframework.scheduling.quartz; import java.io.IOException; import java.util.Map; import java.util.Properties; import java.util.concurrent.Executor; import java.util.concurrent.TimeUnit; import javax.sql.DataSource; import org.quartz.Scheduler; import org.quartz.SchedulerException; import org.quartz.SchedulerFactory; import org.quartz.impl.RemoteScheduler; import org.quartz.impl.SchedulerRepository; import org.quartz.impl.StdSchedulerFactory; import org.quartz.simpl.SimpleThreadPool; import org.quartz.spi.JobFactory; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.BeanNameAware; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.context.SmartLifecycle; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; import org.springframework.core.io.support.PropertiesLoaderUtils; import org.springframework.lang.Nullable; import org.springframework.scheduling.SchedulingException; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; /** * {@link FactoryBean} that creates and configures a Quartz {@link org.quartz.Scheduler}, * manages its lifecycle as part of the Spring application context, and exposes the * Scheduler as bean reference for dependency injection. * * Allows registration of JobDetails, Calendars and Triggers, automatically * starting the scheduler on initialization and shutting it down on destruction. * In scenarios that just require static registration of jobs at startup, there * is no need to access the Scheduler instance itself in application code. * * For dynamic registration of jobs at runtime, use a bean reference to * this SchedulerFactoryBean to get direct access to the Quartz Scheduler * ({@code org.quartz.Scheduler}). This allows you to create new jobs * and triggers, and also to control and monitor the entire Scheduler. * * Note that Quartz instantiates a new Job for each execution, in * contrast to Timer which uses a TimerTask instance that is shared * between repeated executions. Just JobDetail descriptors are shared. * * When using persistent jobs, it is strongly recommended to perform all * operations on the Scheduler within Spring-managed (or plain JTA) transactions. * Else, database locking will not properly work and might even break. * (See {@link #setDataSource setDataSource} javadoc for details.) * * The preferred way to achieve transactional execution is to demarcate * declarative transactions at the business facade level, which will * automatically apply to Scheduler operations performed within those scopes. * Alternatively, you may add transactional advice for the Scheduler itself. * * Compatible with Quartz 2.1.4 and higher, as of Spring 4.1. * * @author Juergen Hoeller * @since 18.02.2004 * @see #setDataSource * @see org.quartz.Scheduler * @see org.quartz.SchedulerFactory * @see org.quartz.impl.StdSchedulerFactory * @see org.springframework.transaction.interceptor.TransactionProxyFactoryBean */ public class SchedulerFactoryBean extends SchedulerAccessor implements FactoryBean<Scheduler>, BeanNameAware, ApplicationContextAware, InitializingBean, DisposableBean, SmartLifecycle { /** * The thread count property. */ public static final String PROP_THREAD_COUNT = "org.quartz.threadPool.threadCount"; /** * The default thread count. */ public static final int DEFAULT_THREAD_COUNT = 10; private static final ThreadLocal<ResourceLoader> configTimeResourceLoaderHolder = new ThreadLocal<>(); private static final ThreadLocal<Executor> configTimeTaskExecutorHolder = new ThreadLocal<>(); private static final ThreadLocal<DataSource> configTimeDataSourceHolder = new ThreadLocal<>(); private static final ThreadLocal<DataSource> configTimeNonTransactionalDataSourceHolder = new ThreadLocal<>(); /** * Return the {@link ResourceLoader} for the currently configured Quartz Scheduler, * to be used by {@link ResourceLoaderClassLoadHelper}. * This instance will be set before initialization of the corresponding Scheduler, * and reset immediately afterwards. It is thus only available during configuration. * @see #setApplicationContext * @see ResourceLoaderClassLoadHelper */ @Nullable public static ResourceLoader getConfigTimeResourceLoader() { return configTimeResourceLoaderHolder.get(); } /** * Return the {@link Executor} for the currently configured Quartz Scheduler, * to be used by {@link LocalTaskExecutorThreadPool}. * This instance will be set before initialization of the corresponding Scheduler, * and reset immediately afterwards. It is thus only available during configuration. * @since 2.0 * @see #setTaskExecutor * @see LocalTaskExecutorThreadPool */ @Nullable public static Executor getConfigTimeTaskExecutor() { return configTimeTaskExecutorHolder.get(); } /** * Return the {@link DataSource} for the currently configured Quartz Scheduler, * to be used by {@link LocalDataSourceJobStore}. * This instance will be set before initialization of the corresponding Scheduler, * and reset immediately afterwards. It is thus only available during configuration. * @since 1.1 * @see #setDataSource * @see LocalDataSourceJobStore */ @Nullable public static DataSource getConfigTimeDataSource() { return configTimeDataSourceHolder.get(); } /** * Return the non-transactional {@link DataSource} for the currently configured * Quartz Scheduler, to be used by {@link LocalDataSourceJobStore}. * This instance will be set before initialization of the corresponding Scheduler, * and reset immediately afterwards. It is thus only available during configuration. * @since 1.1 * @see #setNonTransactionalDataSource * @see LocalDataSourceJobStore */ @Nullable public static DataSource getConfigTimeNonTransactionalDataSource() { return configTimeNonTransactionalDataSourceHolder.get(); } @Nullable private SchedulerFactory schedulerFactory; private Class<? extends SchedulerFactory> schedulerFactoryClass = StdSchedulerFactory.class; @Nullable private String schedulerName; @Nullable private Resource configLocation; @Nullable private Properties quartzProperties; @Nullable private Executor taskExecutor; @Nullable private DataSource dataSource; @Nullable private DataSource nonTransactionalDataSource; @Nullable private Map<String, ?> schedulerContextMap; @Nullable private String applicationContextSchedulerContextKey; @Nullable private JobFactory jobFactory; private boolean jobFactorySet = false; private boolean autoStartup = true; private int startupDelay = 0; private int phase = DEFAULT_PHASE; private boolean exposeSchedulerInRepository = false; private boolean waitForJobsToCompleteOnShutdown = false; @Nullable private String beanName; @Nullable private ApplicationContext applicationContext; @Nullable private Scheduler scheduler; /** * Set an external Quartz {@link SchedulerFactory} instance to use. * Default is an internal {@link StdSchedulerFactory} instance. If this method is * called, it overrides any class specified through {@link #setSchedulerFactoryClass} * as well as any settings specified through {@link #setConfigLocation}, * {@link #setQuartzProperties}, {@link #setTaskExecutor} or {@link #setDataSource}. * NOTE: With an externally provided {@code SchedulerFactory} instance, * local settings such as {@link #setConfigLocation} or {@link #setQuartzProperties} * will be ignored here in {@code SchedulerFactoryBean}, expecting the external * {@code SchedulerFactory} instance to get initialized on its own. * @since 4.3.15 * @see #setSchedulerFactoryClass */ public void setSchedulerFactory(SchedulerFactory schedulerFactory) { this.schedulerFactory = schedulerFactory; } /** * Set the Quartz {@link SchedulerFactory} implementation to use. * Default is the {@link StdSchedulerFactory} class, reading in the standard * {@code quartz.properties} from {@code quartz.jar}. For applying custom Quartz * properties, specify {@link #setConfigLocation "configLocation"} and/or * {@link #setQuartzProperties "quartzProperties"} etc on this local * {@code SchedulerFactoryBean} instance. * @see org.quartz.impl.StdSchedulerFactory * @see #setConfigLocation * @see #setQuartzProperties * @see #setTaskExecutor * @see #setDataSource */ public void setSchedulerFactoryClass(Class<? extends SchedulerFactory> schedulerFactoryClass) { this.schedulerFactoryClass = schedulerFactoryClass; } /** * Set the name of the Scheduler to create via the SchedulerFactory, as an * alternative to the {@code org.quartz.scheduler.instanceName} property. * If not specified, the name will be taken from Quartz properties * ({@code org.quartz.scheduler.instanceName}), or from the declared * {@code SchedulerFactoryBean} bean name as a fallback. * @see #setBeanName * @see StdSchedulerFactory#PROP_SCHED_INSTANCE_NAME * @see org.quartz.SchedulerFactory#getScheduler() * @see org.quartz.SchedulerFactory#getScheduler(String) */ public void setSchedulerName(String schedulerName) { this.schedulerName = schedulerName; } /** * Set the location of the Quartz properties config file, for example * as classpath resource "classpath:quartz.properties". * Note: Can be omitted when all necessary properties are specified * locally via this bean, or when relying on Quartz' default configuration. * @see #setQuartzProperties */ public void setConfigLocation(Resource configLocation) { this.configLocation = configLocation; } /** * Set Quartz properties, like "org.quartz.threadPool.class". * Can be used to override values in a Quartz properties config file, * or to specify all necessary properties locally. * @see #setConfigLocation */ public void setQuartzProperties(Properties quartzProperties) { this.quartzProperties = quartzProperties; } /** * Set a Spring-managed {@link Executor} to use as Quartz backend. * Exposed as thread pool through the Quartz SPI. * Can be used to assign a local JDK ThreadPoolExecutor or a CommonJ * WorkManager as Quartz backend, to avoid Quartz's manual thread creation. * By default, a Quartz SimpleThreadPool will be used, configured through * the corresponding Quartz properties. * @since 2.0 * @see #setQuartzProperties * @see LocalTaskExecutorThreadPool * @see org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor * @see org.springframework.scheduling.concurrent.DefaultManagedTaskExecutor */ public void setTaskExecutor(Executor taskExecutor) { this.taskExecutor = taskExecutor; } /** * Set the default {@link DataSource} to be used by the Scheduler. * Note: If this is set, the Quartz settings should not define * a job store "dataSource" to avoid meaningless double configuration. * Also, do not define a "org.quartz.jobStore.class" property at all. * (You may explicitly define Spring's {@link LocalDataSourceJobStore} * but that's the default when using this method anyway.) * A Spring-specific subclass of Quartz' JobStoreCMT will be used. * It is therefore strongly recommended to perform all operations on * the Scheduler within Spring-managed (or plain JTA) transactions. * Else, database locking will not properly work and might even break * (for example, if trying to obtain a lock on Oracle without a transaction). * Supports both transactional and non-transactional DataSource access. * With a non-XA DataSource and local Spring transactions, a single DataSource * argument is sufficient. In case of an XA DataSource and global JTA transactions, * SchedulerFactoryBean's "nonTransactionalDataSource" property should be set, * passing in a non-XA DataSource that will not participate in global transactions. * @since 1.1 * @see #setNonTransactionalDataSource * @see #setQuartzProperties * @see #setTransactionManager * @see LocalDataSourceJobStore */ public void setDataSource(DataSource dataSource) { this.dataSource = dataSource; } /** * Set the {@link DataSource} to be used for non-transactional access. * This is only necessary if the default DataSource is an XA DataSource that will * always participate in transactions: A non-XA version of that DataSource should * be specified as "nonTransactionalDataSource" in such a scenario. * This is not relevant with a local DataSource instance and Spring transactions. * Specifying a single default DataSource as "dataSource" is sufficient there. * @since 1.1 * @see #setDataSource * @see LocalDataSourceJobStore */ public void setNonTransactionalDataSource(DataSource nonTransactionalDataSource) { this.nonTransactionalDataSource = nonTransactionalDataSource; } /** * Register objects in the Scheduler context via a given Map. * These objects will be available to any Job that runs in this Scheduler. * Note: When using persistent Jobs whose JobDetail will be kept in the * database, do not put Spring-managed beans or an ApplicationContext * reference into the JobDataMap but rather into the SchedulerContext. * @param schedulerContextAsMap a Map with String keys and any objects as * values (for example Spring-managed beans) * @see JobDetailFactoryBean#setJobDataAsMap */ public void setSchedulerContextAsMap(Map<String, ?> schedulerContextAsMap) { this.schedulerContextMap = schedulerContextAsMap; } /** * Set the key of an {@link ApplicationContext} reference to expose in the * SchedulerContext, for example "applicationContext". Default is none. * Only applicable when running in a Spring ApplicationContext. * Note: When using persistent Jobs whose JobDetail will be kept in the * database, do not put an ApplicationContext reference into the JobDataMap * but rather into the SchedulerContext. * In case of a QuartzJobBean, the reference will be applied to the Job * instance as bean property. An "applicationContext" attribute will * correspond to a "setApplicationContext" method in that scenario. * Note that BeanFactory callback interfaces like ApplicationContextAware * are not automatically applied to Quartz Job instances, because Quartz * itself is responsible for the lifecycle of its Jobs. * @see JobDetailFactoryBean#setApplicationContextJobDataKey * @see org.springframework.context.ApplicationContext */ public void setApplicationContextSchedulerContextKey(String applicationContextSchedulerContextKey) { this.applicationContextSchedulerContextKey = applicationContextSchedulerContextKey; } /** * Set the Quartz {@link JobFactory} to use for this Scheduler. * Default is Spring's {@link AdaptableJobFactory}, which supports * {@link java.lang.Runnable} objects as well as standard Quartz * {@link org.quartz.Job} instances. Note that this default only applies * to a local Scheduler, not to a RemoteScheduler (where setting * a custom JobFactory is not supported by Quartz). * Specify an instance of Spring's {@link SpringBeanJobFactory} here * (typically as an inner bean definition) to automatically populate a job's * bean properties from the specified job data map and scheduler context. * @since 2.0 * @see AdaptableJobFactory * @see SpringBeanJobFactory */ public void setJobFactory(JobFactory jobFactory) { this.jobFactory = jobFactory; this.jobFactorySet = true; } /** * Set whether to automatically start the scheduler after initialization. * Default is "true"; set this to "false" to allow for manual startup. */ public void setAutoStartup(boolean autoStartup) { this.autoStartup = autoStartup; } /** * Return whether this scheduler is configured for auto-startup. If "true", * the scheduler will start after the context is refreshed and after the * start delay, if any. */ @Override public boolean isAutoStartup() { return this.autoStartup; } /** * Specify the phase in which this scheduler should be started and stopped. * The startup order proceeds from lowest to highest, and the shutdown order * is the reverse of that. By default this value is {@code Integer.MAX_VALUE} * meaning that this scheduler starts as late as possible and stops as soon * as possible. * @since 3.0 */ public void setPhase(int phase) { this.phase = phase; } /** * Return the phase in which this scheduler will be started and stopped. */ @Override public int getPhase() { return this.phase; } /** * Set the number of seconds to wait after initialization before * starting the scheduler asynchronously. Default is 0, meaning * immediate synchronous startup on initialization of this bean. * Setting this to 10 or 20 seconds makes sense if no jobs * should be run before the entire application has started up. */ public void setStartupDelay(int startupDelay) { this.startupDelay = startupDelay; } /** * Set whether to expose the Spring-managed {@link Scheduler} instance in the * Quartz {@link SchedulerRepository}. Default is "false", since the Spring-managed * Scheduler is usually exclusively intended for access within the Spring context. * Switch this flag to "true" in order to expose the Scheduler globally. * This is not recommended unless you have an existing Spring application that * relies on this behavior. Note that such global exposure was the accidental * default in earlier Spring versions; this has been fixed as of Spring 2.5.6. */ public void setExposeSchedulerInRepository(boolean exposeSchedulerInRepository) { this.exposeSchedulerInRepository = exposeSchedulerInRepository; } /** * Set whether to wait for running jobs to complete on shutdown. * Default is "false". Switch this to "true" if you prefer * fully completed jobs at the expense of a longer shutdown phase. * @see org.quartz.Scheduler#shutdown(boolean) */ public void setWaitForJobsToCompleteOnShutdown(boolean waitForJobsToCompleteOnShutdown) { this.waitForJobsToCompleteOnShutdown = waitForJobsToCompleteOnShutdown; } @Override public void setBeanName(String name) { this.beanName = name; } @Override public void setApplicationContext(ApplicationContext applicationContext) { this.applicationContext = applicationContext; } //--------------------------------------------------------------------- // Implementation of InitializingBean interface //--------------------------------------------------------------------- @Override public void afterPropertiesSet() throws Exception { if (this.dataSource == null && this.nonTransactionalDataSource != null) { this.dataSource = this.nonTransactionalDataSource; } if (this.applicationContext != null && this.resourceLoader == null) { this.resourceLoader = this.applicationContext; } // Initialize the Scheduler instance... this.scheduler = prepareScheduler(prepareSchedulerFactory()); try { registerListeners(); registerJobsAndTriggers(); } catch (Exception ex) { try { this.scheduler.shutdown(true); } catch (Exception ex2) { logger.debug("Scheduler shutdown exception after registration failure", ex2); } throw ex; } } /** * Create a SchedulerFactory if necessary and apply locally defined Quartz properties to it. * @return the initialized SchedulerFactory */ private SchedulerFactory prepareSchedulerFactory() throws SchedulerException, IOException { SchedulerFactory schedulerFactory = this.schedulerFactory; if (schedulerFactory == null) { // Create local SchedulerFactory instance (typically a StdSchedulerFactory) schedulerFactory = BeanUtils.instantiateClass(this.schedulerFactoryClass); if (schedulerFactory instanceof StdSchedulerFactory stdSchedulerFactory) { initSchedulerFactory(stdSchedulerFactory); } else if (this.configLocation != null || this.quartzProperties != null || this.taskExecutor != null || this.dataSource != null) { throw new IllegalArgumentException( "StdSchedulerFactory required for applying Quartz properties: " + schedulerFactory); } // Otherwise, no local settings to be applied via StdSchedulerFactory.initialize(Properties) } // Otherwise, assume that externally provided factory has been initialized with appropriate settings return schedulerFactory; } /** * Initialize the given SchedulerFactory, applying locally defined Quartz properties to it. * @param schedulerFactory the SchedulerFactory to initialize */ private void initSchedulerFactory(StdSchedulerFactory schedulerFactory) throws SchedulerException, IOException { Properties mergedProps = new Properties(); if (this.resourceLoader != null) { mergedProps.setProperty(StdSchedulerFactory.PROP_SCHED_CLASS_LOAD_HELPER_CLASS, ResourceLoaderClassLoadHelper.class.getName()); } if (this.taskExecutor != null) { mergedProps.setProperty(StdSchedulerFactory.PROP_THREAD_POOL_CLASS, LocalTaskExecutorThreadPool.class.getName()); } else { // Set necessary default properties here, as Quartz will not apply // its default configuration when explicitly given properties. mergedProps.setProperty(StdSchedulerFactory.PROP_THREAD_POOL_CLASS, SimpleThreadPool.class.getName()); mergedProps.setProperty(PROP_THREAD_COUNT, Integer.toString(DEFAULT_THREAD_COUNT)); } if (this.configLocation != null) { if (logger.isDebugEnabled()) { logger.debug("Loading Quartz config from [" + this.configLocation + "]"); } PropertiesLoaderUtils.fillProperties(mergedProps, this.configLocation); } CollectionUtils.mergePropertiesIntoMap(this.quartzProperties, mergedProps); if (this.dataSource != null) { mergedProps.putIfAbsent(StdSchedulerFactory.PROP_JOB_STORE_CLASS, LocalDataSourceJobStore.class.getName()); } // Determine scheduler name across local settings and Quartz properties... if (this.schedulerName != null) { mergedProps.setProperty(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME, this.schedulerName); } else { String nameProp = mergedProps.getProperty(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME); if (nameProp != null) { this.schedulerName = nameProp; } else if (this.beanName != null) { mergedProps.setProperty(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME, this.beanName); this.schedulerName = this.beanName; } } schedulerFactory.initialize(mergedProps); } private Scheduler prepareScheduler(SchedulerFactory schedulerFactory) throws SchedulerException { if (this.resourceLoader != null) { // Make given ResourceLoader available for SchedulerFactory configuration. configTimeResourceLoaderHolder.set(this.resourceLoader); } if (this.taskExecutor != null) { // Make given TaskExecutor available for SchedulerFactory configuration. configTimeTaskExecutorHolder.set(this.taskExecutor); } if (this.dataSource != null) { // Make given DataSource available for SchedulerFactory configuration. configTimeDataSourceHolder.set(this.dataSource); } if (this.nonTransactionalDataSource != null) { // Make given non-transactional DataSource available for SchedulerFactory configuration. configTimeNonTransactionalDataSourceHolder.set(this.nonTransactionalDataSource); } // Get Scheduler instance from SchedulerFactory. try { Scheduler scheduler = createScheduler(schedulerFactory, this.schedulerName); populateSchedulerContext(scheduler); if (!this.jobFactorySet && !(scheduler instanceof RemoteScheduler)) { // Use AdaptableJobFactory as default for a local Scheduler, unless when // explicitly given a null value through the "jobFactory" bean property. this.jobFactory = new AdaptableJobFactory(); } if (this.jobFactory != null) { if (this.applicationContext != null && this.jobFactory instanceof ApplicationContextAware applicationContextAware) { applicationContextAware.setApplicationContext(this.applicationContext); } if (this.jobFactory instanceof SchedulerContextAware schedulerContextAware) { schedulerContextAware.setSchedulerContext(scheduler.getContext()); } scheduler.setJobFactory(this.jobFactory); } return scheduler; } finally { if (this.resourceLoader != null) { configTimeResourceLoaderHolder.remove(); } if (this.taskExecutor != null) { configTimeTaskExecutorHolder.remove(); } if (this.dataSource != null) { configTimeDataSourceHolder.remove(); } if (this.nonTransactionalDataSource != null) { configTimeNonTransactionalDataSourceHolder.remove(); } } } /** * Create the Scheduler instance for the given factory and scheduler name. * Called by {@link #afterPropertiesSet}. * The default implementation invokes SchedulerFactory's {@code getScheduler} * method. Can be overridden for custom Scheduler creation. * @param schedulerFactory the factory to create the Scheduler with * @param schedulerName the name of the scheduler to create * @return the Scheduler instance * @throws SchedulerException if thrown by Quartz methods * @see #afterPropertiesSet * @see org.quartz.SchedulerFactory#getScheduler */ @SuppressWarnings("NullAway") protected Scheduler createScheduler(SchedulerFactory schedulerFactory, @Nullable String schedulerName) throws SchedulerException { // Override thread context ClassLoader to work around naive Quartz ClassLoadHelper loading. Thread currentThread = Thread.currentThread(); ClassLoader threadContextClassLoader = currentThread.getContextClassLoader(); boolean overrideClassLoader = (this.resourceLoader != null && this.resourceLoader.getClassLoader() != threadContextClassLoader); if (overrideClassLoader) { currentThread.setContextClassLoader(this.resourceLoader.getClassLoader()); } try { SchedulerRepository repository = SchedulerRepository.getInstance(); synchronized (repository) { Scheduler existingScheduler = (schedulerName != null ? repository.lookup(schedulerName) : null); Scheduler newScheduler = schedulerFactory.getScheduler(); if (newScheduler == existingScheduler) { throw new IllegalStateException("Active Scheduler of name '" + schedulerName + "' already registered " + "in Quartz SchedulerRepository. Cannot create a new Spring-managed Scheduler of the same name!"); } if (!this.exposeSchedulerInRepository) { // Need to remove it in this case, since Quartz shares the Scheduler instance by default! SchedulerRepository.getInstance().remove(newScheduler.getSchedulerName()); } return newScheduler; } } finally { if (overrideClassLoader) { // Reset original thread context ClassLoader. currentThread.setContextClassLoader(threadContextClassLoader); } } } /** * Expose the specified context attributes and/or the current * ApplicationContext in the Quartz SchedulerContext. */ private void populateSchedulerContext(Scheduler scheduler) throws SchedulerException { // Put specified objects into Scheduler context. if (this.schedulerContextMap != null) { scheduler.getContext().putAll(this.schedulerContextMap); } // Register ApplicationContext in Scheduler context. if (this.applicationContextSchedulerContextKey != null) { if (this.applicationContext == null) { throw new IllegalStateException( "SchedulerFactoryBean needs to be set up in an ApplicationContext " + "to be able to handle an 'applicationContextSchedulerContextKey'"); } scheduler.getContext().put(this.applicationContextSchedulerContextKey, this.applicationContext); } } /** * Start the Quartz Scheduler, respecting the "startupDelay" setting. * @param scheduler the Scheduler to start * @param startupDelay the number of seconds to wait before starting * the Scheduler asynchronously */ protected void startScheduler(final Scheduler scheduler, final int startupDelay) throws SchedulerException { if (startupDelay <= 0) { logger.info("Starting Quartz Scheduler now"); scheduler.start(); } else { if (logger.isInfoEnabled()) { logger.info("Will start Quartz Scheduler [" + scheduler.getSchedulerName() + "] in " + startupDelay + " seconds"); } // Not using the Quartz startDelayed method since we explicitly want a daemon // thread here, not keeping the JVM alive in case of all other threads ending. Thread schedulerThread = new Thread(() -> { try { TimeUnit.SECONDS.sleep(startupDelay); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); // simply proceed } if (logger.isInfoEnabled()) { logger.info("Starting Quartz Scheduler now, after delay of " + startupDelay + " seconds"); } try { scheduler.start(); } catch (SchedulerException ex) { throw new SchedulingException("Could not start Quartz Scheduler after delay", ex); } }); schedulerThread.setName("Quartz Scheduler [" + scheduler.getSchedulerName() + "]"); schedulerThread.setDaemon(true); schedulerThread.start(); } } //--------------------------------------------------------------------- // Implementation of FactoryBean interface //--------------------------------------------------------------------- @Override public Scheduler getScheduler() { Assert.state(this.scheduler != null, "No Scheduler set"); return this.scheduler; } @Override @Nullable public Scheduler getObject() { return this.scheduler; } @Override public Class<? extends Scheduler> getObjectType() { return (this.scheduler != null ? this.scheduler.getClass() : Scheduler.class); } @Override public boolean isSingleton() { return true; } //--------------------------------------------------------------------- // Implementation of SmartLifecycle interface //--------------------------------------------------------------------- @Override public void start() throws SchedulingException { if (this.scheduler != null) { try { startScheduler(this.scheduler, this.startupDelay); } catch (SchedulerException ex) { throw new SchedulingException("Could not start Quartz Scheduler", ex); } } } @Override public void stop() throws SchedulingException { if (this.scheduler != null) { try { this.scheduler.standby(); } catch (SchedulerException ex) { throw new SchedulingException("Could not stop Quartz Scheduler", ex); } } } @Override public boolean isRunning() throws SchedulingException { if (this.scheduler != null) { try { return !this.scheduler.isInStandbyMode(); } catch (SchedulerException ex) { return false; } } return false; } //--------------------------------------------------------------------- // Implementation of DisposableBean interface //--------------------------------------------------------------------- /** * Shut down the Quartz scheduler on bean factory shutdown, * stopping all scheduled jobs. */ @Override public void destroy() throws SchedulerException { if (this.scheduler != null) { logger.info("Shutting down Quartz Scheduler"); this.scheduler.shutdown(this.waitForJobsToCompleteOnShutdown); } } } 我看到的start和你的不一样

最新推荐

recommend-type

微软内部资料-SQL性能优化3

For an example of how to decode value from this column using the information above, let us assume we have the following value: 0x000705001F83D775010002014F0BEC4E With byte swapping within each ...
recommend-type

CM311-5 ZG鸿蒙开机乐家-降级包.zip

CM311-5 ZG鸿蒙开机乐家-降级包.zip
recommend-type

四桥臂三相逆变器动态电压恢复器 MATLAB仿真

四桥臂三相逆变器动态电压恢复器MATLAB仿真模型简介。资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
recommend-type

复杂背景下票据识别、裁剪与压缩处理 DLL 库

资源下载链接为: https://pan.quark.cn/s/933293380ad9 复杂背景下票据识别、裁剪与压缩处理 DLL 库(最新、最全版本!打开链接下载即可用!)
recommend-type

基于图像处理的安检违禁物品识别

资源下载链接为: https://pan.quark.cn/s/5efbf764ee8c 基于图像处理的安检违禁物品识别(最新、最全版本!打开链接下载即可用!)
recommend-type

PKID查壳工具最新版发布,轻松识别安卓安装包加壳

根据提供的文件信息,我们可以详细解读以下知识点: ### PKiD(查壳)工具介绍 #### 标题分析 - **PKiD(查壳)**: 这是一个专门用于分析安卓安装包(APK文件)是否被加壳的应用程序。"查壳"是一种用于检测软件是否被保护层(即“壳”)包裹的技术术语。加壳是一种常见的软件保护手段,用于隐藏真实的代码逻辑,防止恶意逆向分析。 - **RAR格式文件**: 文件使用了RAR格式进行压缩,这是WinRAR软件用于文件压缩和解压缩的专有格式。 #### 描述分析 - **ApkScan-PKID查壳工具.zip**: 这指的是一款名为ApkScan的工具,它包含了PKID查壳功能。该工具被打包成ZIP格式,便于用户下载和使用。 - **安卓安装包**: 这是指Android平台的应用程序安装包,通常以APK作为文件扩展名。 - **加壳检测**: PKID查壳工具用于检测APK文件是否被加壳,加壳是一种常见的软件保护技术,用于加密和保护软件免遭逆向工程。 - **脱壳测试**: 如果检测到加壳,脱壳测试将用于尝试去除或绕过保护层,以便进行安全分析、调试或修改程序。 #### 标签分析 - **查壳**: 再次强调了工具的主要功能,即检测APK文件中的加壳情况。 - **最新版**: 表示这个文件是PKID查壳工具的最新版本。 - **PKID**: 这是工具的核心名称,代表着该软件的主要功能和用途。 #### 文件列表分析 - **PKiD(查壳).exe**: 这是一个可执行文件,说明PKID查壳工具是一个独立的应用程序,用户可以通过双击此文件直接运行程序,而无需安装。 ### 技术背景 #### 查壳工具的工作原理 查壳工具通常通过分析APK文件的头部信息、资源文件和代码段来检测加壳。它可能会检查PE文件格式的特定区域(APK基于DEX,但PE检查的概念相似),这些区域在加壳过程中可能会被特定的代码模式、字符串或签名标记。例如,某些壳会在文件头部加入特定的字符串,或者修改方法计数等信息。 #### 加壳技术 加壳技术通常用于防止软件被轻易反编译或逆向工程。它可以阻止潜在的窃取知识产权、绕过付费或防止代码分析等。加壳过程包括加密和压缩原始代码,然后在运行时解压和解密代码以供执行。 #### 脱壳技术 脱壳技术是指绕过或移除软件保护壳的过程。这通常需要对壳的工作原理有深入了解,并且需要一定的逆向工程技能。脱壳过程可能包括识别壳的签名、分析保护机制、修改代码和重定位等步骤。 #### 安全测试与逆向工程 查壳工具对于安全测试和逆向工程人员来说是非常重要的工具。它们可以帮助识别软件是否被加壳,从而决定是否需要进行脱壳操作以便深入分析软件的安全漏洞或版权问题。 #### 使用场景 - **安全测试**: 安全工程师在对移动应用程序进行安全评估时,需要确认是否有必要进行脱壳处理。 - **逆向工程**: 开发人员可能需要逆向工程某个应用,以更好地理解其工作原理或为了兼容性问题进行修改。 - **软件保护**: 对于软件开发者而言,了解常见的加壳和脱壳技术有助于更好地保护自己的应用免遭未授权的篡改和分析。 ### 结论 了解和掌握PKID查壳工具的使用对于任何需要对APK文件进行安全性分析的专业人士来说都是基础且关键的技能。该工具提供了一种快速判断软件是否加壳的方法,而且在发现壳的情况下,还可以推测出壳的来源公司,这对于后续的分析和处理提供了便利。然而,值得注意的是,进行脱壳操作往往需要对原始程序代码进行逆向工程,这在很多情况下可能涉及法律和道德问题,因此在使用此类工具时,必须确保其合法性和符合道德规范。
recommend-type

【心理学火柴人视频制作秘籍】:Coze工作流全攻略,带你从入门到精通

# 1. 心理学火柴人视频制作概述 ## 1.1 创作心理学火柴人视频的动机 心理学火柴人视频作为一种富有创意的视觉传达方式,不仅能够将复杂的心理学理论变得生动和易于理解,而且还能为观众提供轻松愉悦的学习体验。这种视频通常采用简化的角色——火柴人,通过动画的形式演绎心理学相关的内容,使得原本抽象的理论变得具体、形象。 ## 1.2 火柴人视频的普及与应用 随着互联
recommend-type

frame.onload不执行?

<think>在解决`frame.onload`不执行的问题时,我们需要考虑多种可能的原因和解决方案。下面我将详细解释这个问题,并提供相应的代码示例。##可能的原因及解决方案###1.事件绑定时机不正确如果我们在设置`src`属性之后再绑定`onload`事件,可能会错过事件的触发(因为资源可能已经加载完成)。所以,我们应该在设置`src`之前绑定`onload`事件。###2.资源加载失败如果资源加载失败,`onload`事件可能不会触发,而触发`onerror`事件。因此,我们需要同时监听`onerror`事件。###3.iframe内容为空如果我们使用`document.write`来设
recommend-type

一键关闭系统更新的工具介绍

从给定的文件信息中我们可以分析出几个相关的知识点,以下是详细说明: 【标题】“系统禁止更新工具.7z”暗示着这个压缩文件内包含的可能是一款软件工具,其主要功能是阻止或禁止操作系统的更新。这种工具可能针对的是Windows、Linux或者其他操作系统的自动更新功能。一般来说,用户可能出于稳定性考虑,希望控制更新时间,或者是因为特定的软件环境依赖于旧版本的系统兼容性,不希望系统自动更新导致兼容性问题。 【描述】“一健关闭系统更新”说明了该工具的使用方式非常简单直接。用户只需通过简单的操作,比如点击一个按钮或者执行一个命令,就能实现关闭系统自动更新的目的。这种一键式操作符合用户追求的易用性原则,使得不太精通系统操作的用户也能轻松控制更新设置。 【标签】“系统工具”表明这是一个与操作系统紧密相关的辅助工具。系统工具通常包括系统清理、性能优化、磁盘管理等多种功能,而本工具专注于管理系统更新,使其成为系统维护中的一环。 【压缩包子文件的文件名称列表】“系统禁止更新工具”是压缩包内的文件名。由于文件格式为“.7z”,这说明该工具采用了7-Zip压缩格式。7-Zip是一款开源且免费的压缩软件,支持非常高的压缩比,并且能够处理各种压缩文件格式,如ZIP、RAR等。它支持创建密码保护的压缩文件和分卷压缩,这在需要转移大量数据时特别有用。然而在这个上下文中,“系统禁止更新工具”文件名暗示了该压缩包内只包含了一个程序,即专门用于关闭系统更新的工具。 根据标题和描述,我们可以推测该工具可能的实现机制,例如: 1. 修改系统服务的配置:在Windows系统中,可以通过修改Windows Update服务的属性来禁用该服务,从而阻止系统自动下载和安装更新。 2. 修改注册表设置:通过编辑Windows注册表中的某些特定键值,可以关闭系统更新功能。这通常涉及到对HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate和HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU等路径下的设置进行修改。 3. 使用第三方软件:某些第三方工具提供了一键禁用系统更新的功能,通过修改操作系统的相关文件和配置来实现更新的禁用。这包括阻止Windows Update的运行、拦截更新下载等。 该工具的使用可能带来一些后果,比如系统安全风险的增加、系统漏洞得不到及时修复以及可能违反某些软件许可协议。用户在使用这类工具时应该清楚这些潜在的影响,并自行承担相应的风险。 总结来说,该“系统禁止更新工具”可以视为一个针对特定用户需求,尤其是企业用户或个人用户中对系统稳定性有较高要求的人群,提供的一个便捷的解决方案。它通过直接修改系统设置来禁止操作系统自动更新,但用户在使用此工具时需要谨慎,因为这可能会带来系统安全和稳定性的风险。
recommend-type

罗技GHUB驱动21.03.24版自定义设置与性能优化:专家级使用技巧

# 摘要 本文综合介绍了罗技GHUB驱动的安装、自定义设置、性能优化、进阶应用以及故障排除。通过对GHUB软件界面和功能的详细介绍,阐述了硬件识别、宏命令创建以及游戏特有设置的定制。同时,文中探讨了性能调整的理论基础,并提供实践中针对网络延迟和数据传输优化的具体技巧。进一步探讨了高级个性化配置和第三方软件集成的策略,最后针对