有没有办法加快插入到mdb?
using (StreamReader sr = new StreamReader(_localDir + "\\" + _filename))
while ((line = sr.ReadLine()) != null)
{
//sanitize the data
}
Run Code Online (Sandbox Code Playgroud)
对于来自csv的约2mil记录,这需要大约20秒,但是当我添加mdb插入时,我在10分钟内几乎无法获得10,000条记录,因此您可以看到它将永远需要
using (StreamReader sr = new StreamReader(_localDir + "\\" + _filename))
while ((line = sr.ReadLine()) != null)
{
//sanitize the data
using (OleDbConnection con = new OleDbConnection(_conStr))
using (OleDbCommand cmd = new OleDbCommand())
cmd.Parameters.AddWithValue...//I have 22 params
cmd.ExecuteNonQuery();
}
Run Code Online (Sandbox Code Playgroud)
有没有更好的办法?连接池?线程?这是我的constr Provider = Microsoft.Jet.OLEDB.4.0; Data Source = mypath; Jet OLEDB:Engine Type = 5"
问候
_Eric
使用ejb 3.1,servlet 3.0(glassfish服务器v3)
场景:我有MDB,它监听jms消息并处理其他会话bean(无状态).Servelet注入jms资源.
问题1:为什么servlet在使用静态声明时不能注入jms资源?
@Resource(mappedName = "jms/Tarturus")
private static ConnectionFactory connectionFactory;
@Resource(mappedName = "jms/StyxMDB")
private static Queue queue;
private Connection connection;
Run Code Online (Sandbox Code Playgroud)
和
@PostConstruct
public void postConstruct() {
try {
connection = connectionFactory.createConnection();
} catch (JMSException e) {
e.printStackTrace();
}
}
@PreDestroy
public void preDestroy() {
try {
connection.close();
} catch (JMSException e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
我得到的错误是:
[#| 2010-05-03T15:18:17.118 + 0300 |警告| glassfish3.0 | javax.enterprise.system.container.web.com.sun.enterprise.web | _ThreadID = 35; _ThreadName =线程1; | StandardWrapperValve [WorkerServlet]:PWC1382:为servlet WorkerServlet分配异常com.sun.enterprise.container.common.spi.util.InjectionException:在com.sun上为类ua.co.rufous.server.services.WorkerServiceImpl创建托管对象时出错.企业.container.common.impl.util.InjectionManagerImpl.createManagedObject(InjectionManagerImpl.java:312)位于com.sun.enterprise.web.WebModule的com.sun.enterprise.web.WebContainer.createServletInstance(WebContainer.java:709). createServletInstance(WebModule.java:1937)at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1252)引起:com.sun.enterprise.container.common.spi.util.InjectionException:异常尝试注入未解决的Message-Destination-Ref ua.co.rufous.server.services.WorkerServiceImpl/queue @ …
我想明确设置一个事务在JavaEE MDB中回滚:
private MessageDrivenContext context;
@MessageDriven(mappedName = "jms/ReaderQueue", activationConfig = {
@ActivationConfigProperty(
propertyName = "acknowledgeMode",
propertyValue = "Auto-acknowledge"),
@ActivationConfigProperty(
propertyName = "destinationType",
propertyValue = "javax.jms.Queue")
})
public class MessageReaderBean implements MessageListener {
public void onMessage(Message message) {
ctx.setRollbackOnly(); // <-- see here, my good fellow!
}
public void setMessageDrivenContext(MessageDrivenContext ctx) throws EJBException {
this.context = ctx;
}
}
Run Code Online (Sandbox Code Playgroud)
然而,容器没有打电话setMessageDrivenContext给我,我得到了一个NullPointerException.注入上下文需要什么魔法酱?
我发现这个视频显示了如何连接到访问数据库:
http://www.youtube.com/watch?v=ujJ4H9RpC7c
我的问题是:是否可以以编程方式创建ODBC数据源?
或者从命令行或类似的东西?
谢谢
我希望从我的应用程序中嵌入的HornetQ的所有日志记录委托给slf4j.不幸的是,任何尝 我已经尝试过了
SLF4JBridgeHandler.install();Log4jLogDelegateFactory("hornetq-configuration.xml"经过<log-delegate-factory-class-name>org.hornetq.integration.logging.Log4jLogDelegateFactory</log-delegate-factory-class-name>)LogDelegate和LogDelegateFactory但无论我做什么,下面的线路都没有抓住:
13.07.2011 17:42:11 org.hornetq.core.logging.impl.JULLogDelegate warn
WARNUNG: AIO wasn't located on this platform, it will fall back to using pure Java NIO. If your platform is Linux, install LibAIO to enable the AIO journal
13.07.2011 17:42:11 org.hornetq.core.logging.impl.JULLogDelegate info
INFO: Using NIO Journal
13.07.2011 17:42:11 org.hornetq.core.logging.impl.JULLogDelegate info
INFO: Started Netty Acceptor version 3.1.5.GA-r1772
Run Code Online (Sandbox Code Playgroud)
我错过了什么?
我们有一个应用程序,它读取JMS并执行一些数据库事务,所有这些都作为一个XA事务的一部分.如果我们发现消息有一些问题,我们想要回滚数据库,但我们不希望从JMS回滚让我们再次阅读该消息(如果先前已启动回滚,我们不希望MDB再次触发整个过程).
我们将maxSession的数量限制为5 @ActivationConfigProperty(propertyName ="maxSession",propertyValue ="5") 如果超过5个并发请求,则必须在队列中等待.是否有任何选项可以将队列中的等待消息数作为列表查看并管理队列.是否有任何API可以查看和管理队列.例如,如果JMS消息等待很长时间,使用队列管理我们可以重新发起消息,或者我们可以丢弃消息.
在我的应用程序中,我按如下方式定义了log4j.properites
log4j.appender.email=org.apache.log4j.net.SMTPAppender
log4j.appender.email.Subject=email Notification
Run Code Online (Sandbox Code Playgroud)
后来在程序中我动态地将主题改为
Properties prop = new Properties();
prop.setProperty("log4j.appender.email.Subject", "Test Completed");
Run Code Online (Sandbox Code Playgroud)
使用此变量后,我想将其重置为原始文件.所以我这样做了
LogManager.resetConfiguration();
PropertyConfigurator.configure(prop);
Run Code Online (Sandbox Code Playgroud)
但是,每当我使用这个主题属性时,代码后面的代码都将其值作为"Test Completed".任何重置配置的建议都非常感谢.谢谢
我有2个类,例如A和B.
这些类有几个具有相同名称的getter/setter方法.
现在在代码中我执行以下操作:
if(obj.getClassName().equals(A.class.getName())){
A a = (A) obj;
String result = a.getInfo();
}
else if(obj.getClassName().equals(B.class.getName())){
B a = (B) obj;
String result = a.getInfo();
}
Run Code Online (Sandbox Code Playgroud)
我想知道是否有办法调用getInfo避免if语句.
注意:我无法重构类以使用继承或其他东西.
我只是感兴趣,如果在java中有一个技巧,以避免if语句.
我想问一下异常的根本原因:
Caused by: java.lang.ClassCastException: java.lang.Class cannot be cast to
java.lang.reflect.ParameterizedType
Run Code Online (Sandbox Code Playgroud)
当我们让Spring为类生成代理(即proxy-target-class="true"在事务管理器上设置)时,会发生在Spring中:
<tx:annotation-driven transaction-manager="transactionManager"
proxy-target-class="true"/>
Run Code Online (Sandbox Code Playgroud)
当代理类是参数化类时,即
public class SomeDAOImpl<SomeEntity> implements SomeDAO ...
Run Code Online (Sandbox Code Playgroud)
例如,完整的故事可以在这个问题中阅读:抽象DAO模式和Spring的"代理无法转换为......"问题!
问题:为什么Spring不能代理这个类?是因为它使用旧的代码生成库吗?因为类型擦除?如果它SomeDAOImpl不是泛型类,它会成功(我检查过).
请不要回答:"你应该代理接口,而不是类".我知道.
我们有一个使用 Spring Framework 在 Tomcat 中运行的 Web 应用程序。我们需要为循环操作添加一些预定的作业。我们为此遇到了 Quartz 调度器,并遵循了使用 Quartz 和 Spring 配置作业的教程,并按预期安排和运行了作业。
所以我们有一些任务是在应用程序启动时安排的。现在我们希望用户手动运行作业并更改作业的触发器,但我们需要将这些更改持久化到数据库中。因此,当应用程序启动时,它会读取持久化的任务,如果它们不存在,则从 spring 描述符文件中加载默认任务。
为简单起见,让我们假设我们正在使用示例中的 beans.xml 文件:
<bean id="processToExecute" class="com.mycompany.ProcessToExecute" />
<bean name="processToExecuteJob" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass" value="com.mycompany.ProcessToExecuteJob" />
<property name="jobDataAsMap">
<map>
<entry key="processToExecute" value-ref="processToExecute" />
</map>
</property>
</bean>
<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="processToExecuteJob" />
<property name="cronExpression" value="0/5 * * * * ?" />
</bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="jobDetails">
<list>
<ref bean="processToExecuteJob" />
</list>
</property>
<property name="triggers">
<list>
<ref bean="simpleTrigger" />
</list>
</property> …Run Code Online (Sandbox Code Playgroud) 我必须使用Access 2003 .mdb文件作为数据存储库在Delphi中创建一个程序.
Access数据库有一个表,其中包含一个名为"original"的布尔值(在Access中为Yes/No)字段.
我已将此字段映射到TDBCheckBox,其显示已检查为true且未选中为false,并显示半灰色检查是否尚未设置字段.
我想要的是将字段的字段设置为false(复选框未选中),并将字段值保存为false,如果用户没有明确设置字段.
我试过if(DVDQuery.FieldByName('Original').AsBoolean <> True)和(DVDQuery.FieldByName('Original').AsBoolean <> False)然后是DVDQuery.FieldByName('Original').AsBoolean:= False;
但这对新记录不起作用.我使用查询来访问数据集,因为有大量动态创建的where语句来过滤数据集.
非常感谢您的帮助指导.
抢
我有这样的对象:
@Entity
public class DocumentationRecord {
@Id
@GeneratedValue
private long id;
private String topic;
private boolean isParent;
@OneToMany
private List<DocumentationRecord> children;
...
}
Run Code Online (Sandbox Code Playgroud)
现在我想只获得主题和ID.有没有办法得到这样的格式:
[
{
id: 4234234,
topic: "fsdfsdf"
},...
]
Run Code Online (Sandbox Code Playgroud)
因为即使只使用此查询
public interface DocumentationRecordRepository extends CrudRepository<DocumentationRecord, Long> {
@Query("SELECT d.topic as topic, d.id as id FROM DocumentationRecord d")
List<DocumentationRecord> getAllTopics();
}
Run Code Online (Sandbox Code Playgroud)
我只能得到这样的记录:
[
[
"youngChild topic",
317
],
[
"oldChild topic",
318
],
[
"child topic",
319
],
]
Run Code Online (Sandbox Code Playgroud)
我不喜欢数组数组我想获得具有属性id和主题的对象数组.实现这一目标最好的方法是什么?