以下Java代码用于将文件附加到电子邮件.我想通过电子邮件发送多个文件附件.任何建议,将不胜感激.
public class SendMail {
public SendMail() throws MessagingException {
String host = "smtp.gmail.com";
String Password = "mnmnn";
String from = "xyz@gmail.com";
String toAddress = "abc@gmail.com";
String filename = "C:/Users/hp/Desktop/Write.txt";
// Get system properties
Properties props = System.getProperties();
props.put("mail.smtp.host", host);
props.put("mail.smtps.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
Session session = Session.getInstance(props, null);
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.setRecipients(Message.RecipientType.TO, toAddress);
message.setSubject("JavaMail Attachment");
BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setText("Here's the file");
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
messageBodyPart = new MimeBodyPart(); …Run Code Online (Sandbox Code Playgroud) 以下代码取自JavaDocCondition:
class BoundedBuffer {
final Lock lock = new ReentrantLock();
final Condition notFull = lock.newCondition();
final Condition notEmpty = lock.newCondition();
final Object[] items = new Object[100];
int putptr, takeptr, count;
public void put(Object x) throws InterruptedException {
lock.lock();
try {
while (count == items.length)
notFull.await();
items[putptr] = x;
if (++putptr == items.length) putptr = 0;
++count;
notEmpty.signal();
} finally {
lock.unlock();
}
}
public Object take() throws InterruptedException {
lock.lock();
try {
while (count == 0)
notEmpty.await(); …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Typesafe Activator 1.2.3 的离线安装Play Framework 2.3.2 .每一篇文档都告诉我,它正在使用sbt来构建和运行项目.
这个sbt位于/安装在哪里?它是否在包含Activator安装的解压缩文件夹中的某个位置?
如何从命令行启动sbt?它不是在PATH运行中locate sbt找不到任何东西.
我有这样一张桌子:
date_start date_end account_id product_id
2001-01-01 2001-01-31 1 1
2001-02-01 2001-02-20 1 1
2001-04-01 2001-05-20 1 1
Run Code Online (Sandbox Code Playgroud)
我想禁止给定的重叠间隔 (account_id, product_id)
编辑:我找到了一些东西:
CREATE TABLE test (
from_ts TIMESTAMPTZ,
to_ts TIMESTAMPTZ,
account_id INTEGER,
product_id INTEGER,
CHECK ( from_ts < to_ts ),
CONSTRAINT overlapping_times EXCLUDE USING GIST (
account_id WITH =,
product_id WITH =,
box(
point( extract(epoch FROM from_ts at time zone 'UTC'), extract(epoch FROM from_ts at time zone 'UTC') ),
point( extract(epoch FROM to_ts at time zone 'UTC') , extract(epoch FROM to_ts …Run Code Online (Sandbox Code Playgroud) 在Java中我可以说Integer.MAX_VALUE获得该int类型可以容纳的最大数字.
Postgres中是否有类似的常数/函数?我想避免硬编码.
编辑:我问的原因是这个.存在具有类型ID的遗留表integer,由序列支持.此表中有很多传入的行.我想计算integer耗尽前多长时间,所以我需要知道"剩下多少ID"除以"我们花多少钱".
升级到Eclipse Juno并导入现有Java EE项目后,Tasks视图不会显示我的.java文件中的注释中的TODO.我可以通过专门右键单击装订线并Add Task...从弹出菜单中选择来手动添加新的TODO任务,但Eclipse应该自己从我的注释中创建TODO .
我查看了与任务标签相关的所有首选项,它们都是默认的(因此可以),仍然没有标签出现.我尝试关闭/打开项目,重新构建它,我检查了Git repo,看到没有任何点文件(.project等)被修改,因为在旧的Eclipse中一切都有效.
这个问题对我没有帮助......如何让Eclipse展示我的Java TODO?
如何编写jQuery表达式,找到name属性值与属性值不同的输入id?
应该找到这个
<input name="foo" id="bar" />
Run Code Online (Sandbox Code Playgroud)
这不应该找到
<input name="foo" id="foo" />
Run Code Online (Sandbox Code Playgroud)
琐碎的事情就像$('input[name!=id]')失败一样,因为[]表达式需要在右侧保持不变.
我在Object课堂上添加了一个字段,如:
class Object {
...
private Object _objInfo;
}
Run Code Online (Sandbox Code Playgroud)
我更改了java.lang.Object源代码并重新编译了OpenJDK 6.当VM启动时,我收到以下异常:
Error occurred during initialization of VM
java.lang.IllegalStateException
at java.lang.Throwable.initCause(Throwable.java:337)
at java.lang.ExceptionInInitializerError.<init>(ExceptionInInitializerError.java:79)
Run Code Online (Sandbox Code Playgroud)
当我定义自己的Object类并将其添加到bootclasspath时会出现同样的问题,如:
java -Xbootclasspath/p:<path to my Object class>
Run Code Online (Sandbox Code Playgroud)
谢谢,Horatiu
我在PostgreSQL中有两个我需要联合的数组.例如:
{1,2,3}工会{1,4,5}会回来{1,2,3,4,5}
使用连接(||)运算符不会删除重复的条目,即它返回 {1,2,3,1,4,5}
我在网上找到了一个解决方案,但我不喜欢它需要如何取消两个数组:
select ARRAY(select unnest(ARRAY[1,2,3]) as a UNION select unnest(ARRAY[2,3,4,5]) as a)
是否有一个运算符或内置函数可以干净地结合两个数组?
我ExecutorService用来异步发送邮件,所以有一个类:
class Mailer implements Runnable { ...
Run Code Online (Sandbox Code Playgroud)
处理发送.对于(匿名)示例,将记录捕获的任何异常:
javax.mail.internet.AddressException: foo is bar
at javax.mail.internet.InternetAddress.checkAddress(InternetAddress.java:1213) ~[mail.jar:1.4.5]
at javax.mail.internet.InternetAddress.parse(InternetAddress.java:1091) ~[mail.jar:1.4.5]
at javax.mail.internet.InternetAddress.parse(InternetAddress.java:633) ~[mail.jar:1.4.5]
at javax.mail.internet.InternetAddress.parse(InternetAddress.java:610) ~[mail.jar:1.4.5]
at mycompany.Mailer.sendMail(Mailer.java:107) [Mailer.class:?]
at mycompany.Mailer.run(Mailer.java:88) [Mailer.class:?]
... suppressed 5 lines
at java.lang.Thread.run(Thread.java:680) [?:1.6.0_35]
Run Code Online (Sandbox Code Playgroud)
不是很有帮助 - 我需要看到调用ExecutorService导致所有这一切的堆栈跟踪.我的解决方案是创建一个空Exception并将其传递给Mailer:
executorService.submit(new Mailer(foo, bar, new Exception()));
...
// constructor
public Mailer(foo, bar, Exception cause) { this.cause = cause; ...
Run Code Online (Sandbox Code Playgroud)
现在在异常的情况下,我想从另一个线程记录问题本身及其原因:
try {
// send the mail...
} catch (Throwable t) {
LOG.error("Stuff went …Run Code Online (Sandbox Code Playgroud) java ×5
postgresql ×3
arrays ×1
constants ×1
eclipse ×1
integer ×1
jakarta-mail ×1
jquery ×1
jvm ×1
logging ×1
plpgsql ×1
sbt ×1
sql ×1
stack-trace ×1
union ×1