step 1)
create a property file with name Conn.Properties having example property bvmc.LoginURL=manish
bvdb.url = jdbc:oracle:thin:
step 2)
write the following java code
private static final Properties CONNPRP = new Properties();
static {
try {
FileInputStream fileInputStream = new FileInputStream(
"config/Conn.Properties");
CONNPRP.load(fileInputStream);
} catch (Exception e)
{
throw new RuntimeException(e);
}
}
String loginURL = CONNPRP.getProperty("bvmc.LoginURL");
System.out.println("loginURL :::::: " + loginURL);
Tuesday, February 10, 2009
***** How to create mail functionality in java *****
We just need mail.jar imported into our Eclipse project for this mail functionality.
package Mail;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class MailManager {
private static Properties properties = System.getProperties();
static {
String mailhost = "relay.company.com";
properties.put("mail.smtp.host", mailhost);
properties.put("mail.mime.charset", "utf-8");
}
public static void main(String[] args) throws Throwable {
try {
// System.out.println("Start-----------");
// String userName = "Vikas";
// String from = userName + "@gmail.com";
// String to = "manish.kr.jaiswal@gmail.com";
// String body = "This is the body";
// String subject = "TestSubject";
// sendEmail(from, to, body, subject);
// System.out.println("Start-----------2");
} catch (Throwable th) {
th.printStackTrace();
throw th;
}
}
public static void sendEmail(String from, String to, String body,
String subject) throws MessagingException, AddressException {
Session session = Session.getInstance(properties, null);
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(
to, false));
message.setSubject(subject);
message.setContent(body, "text/html; charset=utf-8");
// message.setText(body);// , "text/html;
Transport.send(message);
}
}
package Mail;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class MailManager {
private static Properties properties = System.getProperties();
static {
String mailhost = "relay.company.com";
properties.put("mail.smtp.host", mailhost);
properties.put("mail.mime.charset", "utf-8");
}
public static void main(String[] args) throws Throwable {
try {
// System.out.println("Start-----------");
// String userName = "Vikas";
// String from = userName + "@gmail.com";
// String to = "manish.kr.jaiswal@gmail.com";
// String body = "This is the body";
// String subject = "TestSubject";
// sendEmail(from, to, body, subject);
// System.out.println("Start-----------2");
} catch (Throwable th) {
th.printStackTrace();
throw th;
}
}
public static void sendEmail(String from, String to, String body,
String subject) throws MessagingException, AddressException {
Session session = Session.getInstance(properties, null);
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(
to, false));
message.setSubject(subject);
message.setContent(body, "text/html; charset=utf-8");
// message.setText(body);// , "text/html;
Transport.send(message);
}
}
Sunday, February 8, 2009
**** Using JSON in JavaScript. *****
JSON Simply is a way of representation of data and its access and this is by default supported by javascript
JSON is a subset of the object literal notation of JavaScript. Since JSON is a subset of JavaScript,
it can be used in the language with no muss or fuss.
var myJSONObject = {"bindings": [
{"ircEvent": "PRIVMSG", "method": "newURI", "regex": "^http://.*"},
{"ircEvent": "PRIVMSG", "method": "deleteURI", "regex": "^delete.*"},
{"ircEvent": "PRIVMSG", "method": "randomURI", "regex": "^random.*"}
]
};
Members can be retrieved using dot or subscript operators.
myJSONObject.bindings[0].method // "newURI"
To convert a JSON text into an object, you can use the eval() function. eval() invokes the JavaScript compiler. Since JSON is a proper subset of JavaScript, the compiler will correctly parse the text and produce an object structure. The text must be wrapped in parens to avoid tripping on an ambiguity in JavaScript's syntax.
var myObject = eval('(' + myJSONtext + ')');
JSON is a subset of the object literal notation of JavaScript. Since JSON is a subset of JavaScript,
it can be used in the language with no muss or fuss.
var myJSONObject = {"bindings": [
{"ircEvent": "PRIVMSG", "method": "newURI", "regex": "^http://.*"},
{"ircEvent": "PRIVMSG", "method": "deleteURI", "regex": "^delete.*"},
{"ircEvent": "PRIVMSG", "method": "randomURI", "regex": "^random.*"}
]
};
Members can be retrieved using dot or subscript operators.
myJSONObject.bindings[0].method // "newURI"
To convert a JSON text into an object, you can use the eval() function. eval() invokes the JavaScript compiler. Since JSON is a proper subset of JavaScript, the compiler will correctly parse the text and produce an object structure. The text must be wrapped in parens to avoid tripping on an ambiguity in JavaScript's syntax.
var myObject = eval('(' + myJSONtext + ')');
Thursday, February 5, 2009
1) Ajax made Simple
Ajax in Simple steps.............ENJOYYYYYYYYY
Basically there are 3 things to be understood in Ajax
1) we have a request state that tells the request state after its being sent from AJAX/javascript code
State Description
0 The request is not initialized
1 The request has been set up
2 The request has been sent
3 The request is in process
4 The request is complete
2) A function is being called at every state of request .
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
// Get the data from the server's response
}
}
4) Get the data from the server's response
xmlHttp.responseText
Now Before all these we need 2 things more
1) get XMLHttpRequest object (its an ActiveXObject ).
2) send the request using
xmlHttp.open("GET","time.asp",true);
xmlHttp.send(null);
Basically there are 3 things to be understood in Ajax
1) we have a request state that tells the request state after its being sent from AJAX/javascript code
State Description
0 The request is not initialized
1 The request has been set up
2 The request has been sent
3 The request is in process
4 The request is complete
2) A function is being called at every state of request .
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
// Get the data from the server's response
}
}
4) Get the data from the server's response
xmlHttp.responseText
Now Before all these we need 2 things more
1) get XMLHttpRequest object (its an ActiveXObject ).
2) send the request using
xmlHttp.open("GET","time.asp",true);
xmlHttp.send(null);
2) JOB SCHEDULING USING QUARTZ IN JAVA
An easy example for JOB scheduling
class 1 MainApplication :-
import java.util.Calendar;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import org.apache.catalina.util.URLEncoder;
class MainApplication {
public static void main(String[] args) {
Timer timer = new Timer();
Calendar date = Calendar.getInstance();
date.set(
Calendar.DAY_OF_WEEK,
Calendar.WEDNESDAY
);
date.set(Calendar.HOUR, 5);
date.set(Calendar.MINUTE,0);
date.set(Calendar.SECOND, 0);
date.set(Calendar.MILLISECOND, 0);
// Schedule to run every Sunday in midnight
timer.schedule(
new ReportGenerator(),
date.getTime(),
1000 * 60 * 60 * 24 * 7
);
}
}
class 2 ReportGenerator :-
import java.util.TimerTask;
public class ReportGenerator extends TimerTask {
public void run() {
System.out.println("This is VIKASSSSSSSSSSSSSSSSSSSSSSSS:: ");
//TODO generate report
}
}
---------------------------------------------------------------
class 1 MainApplication :-
import java.util.Calendar;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import org.apache.catalina.util.URLEncoder;
class MainApplication {
public static void main(String[] args) {
Timer timer = new Timer();
Calendar date = Calendar.getInstance();
date.set(
Calendar.DAY_OF_WEEK,
Calendar.WEDNESDAY
);
date.set(Calendar.HOUR, 5);
date.set(Calendar.MINUTE,0);
date.set(Calendar.SECOND, 0);
date.set(Calendar.MILLISECOND, 0);
// Schedule to run every Sunday in midnight
timer.schedule(
new ReportGenerator(),
date.getTime(),
1000 * 60 * 60 * 24 * 7
);
}
}
class 2 ReportGenerator :-
import java.util.TimerTask;
public class ReportGenerator extends TimerTask {
public void run() {
System.out.println("This is VIKASSSSSSSSSSSSSSSSSSSSSSSS:: ");
//TODO generate report
}
}
---------------------------------------------------------------
Subscribe to:
Posts (Atom)