Exception ex;
ex.printStackTrace(new PrintWriter(out, true));
Exception ex;
StringWriter traceSW = new StringWriter(1000);
PrintWriter tracePW = new PrintWriter(traceSW, true);
ex.printStackTrace(tracePW);
String str = traceSW.toString();
import java.sql.*;
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try
{
Class.forName(theJdbcDriver);
con = DriverManager.getConnection(theDbUrl, theUser, thePasswd);
stmt = con.createStatement();
rs = stmt.executeQuery("select * from dual");
while (rs.next())
{
String val = rs.getString(1);
}
}
finally
{
if (rs != null) {rs.close();}
if (stmt != null) {stmt.close();}
if (con != null) {con.close();}
}
import javax.mail.*;
import javax.mail.internet.*;
// attribute setzen
Properties props = new Properties();
props.setProperty("mail.smtp.host", "localhost");
props.setProperty("mail.smtp.port", "25");
InternetAddress to[] = new InternetAddress[1];
to[0] = new InternetAddress("xxx@yyy");
InternetAddress from = new InternetAddress("xxx@yyy");
String subject = "[test] a subject";
String body = "[test] body";
// mail senden
Session mailsession = Session.getInstance(props, null);
Message message = new MimeMessage(mailsession);
message.setFrom(from);
message.setRecipients(Message.RecipientType.TO, to);
message.setSubject(subject);
message.setContent(body, "text/plain");
Transport.send(message);
import java.net.*;
import java.io.*;
StringBuffer buf = new StringBuffer(2000);
URL url = new URL(urlStr);
InputStream in = url.openStream();
InputStreamReader inR = new InputStreamReader(in);
char ch[] = new char[1000];
int len;
while ((len = inR.read(ch, 0, 1000)) != -1)
{
buf.append(ch, 0, len);
}
String content = buf.toString();
import java.awt.*;
import java.awt.image.*;
/**
* Get a BufferedImage from a Image.
* @param img An Image object.
* @return the BufferedImage
*/
public BufferedImage createBufferedImage(Image img)
{
Canvas c = new Canvas();
try
{
MediaTracker tracker = new MediaTracker(c);
tracker.addImage(img, 0);
tracker.waitForID(0);
}
catch (Exception e) {}
int width = img.getWidth(c);
int height = img.getHeight(c);
BufferedImage bi = new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);
Graphics2D biContext = bi.createGraphics();
biContext.drawImage(img, 0, 0, null);
return bi;
}
import java.io.*;
static final String CODESET = "ISO-8859-1";
/**
* Decode a base64-encoded String.
* @param str a base64-encoded String.
* @return the decoded String
*/
public static String decodeBase64(String str)
throws IOException
{
byte[] inBytes = str.getBytes(CODESET);
ByteArrayInputStream is = new ByteArrayInputStream(inBytes);
sun.misc.BASE64Decoder dec = new sun.misc.BASE64Decoder();
String val = new String(dec.decodeBuffer(is), CODESET);
return val;
}
/**
* Replace all occurences of placeHolder with val.
* @param src String where placeHolder shall be replaced by val
* @param placeHolder to be replaced
* @param val replacement
* @return String with place holders replaced by value
*/
protected String replacePlaceHolders(String src,
String placeHolder, String val)
{
int last = 0;
int next = 0;
int phLen = placeHolder.length();
StringBuffer buf = new StringBuffer(src.length() * 2);
while ((next = src.indexOf(placeHolder, last)) >= 0)
{
buf.append(src.substring(last, next));
buf.append(val);
last = next + phLen;
}
if (last > 0)
{
buf.append(src.substring(last));
}
return (last > 0) ? buf.toString() : src;
}
/**
* Get properties with a given prefix.
* @param props Properties from which we will select certain properties.
* @param prefix The prefix.
* @return The selected properties <em>without</em> the prefix
*/
private Properties getPropsWithPrefix(Properties props,
String prefix)
{
Properties prefixed = new Properties();
if (props != null)
{
Enumeration keys = props.propertyNames();
while (keys.hasMoreElements())
{
String key = (String)keys.nextElement();
if (key.startsWith(prefix))
{
prefixed.setProperty(key.substring(prefix.length()),
props.getProperty(key));
}
}
}
return prefixed;
}
Driver | Type | URL |
---|---|---|
Interbase: interbase.interclient.Driver |
4 | jdbc:interbase://<host>[:<port>]/<path to DB file> |
Firebird: org.firebirdsql.jdbc.FBDriver |
4 | jdbc:firebirdsql://<host>[:<port>]/<path to DB file> |
MySQL: com.mysql.jdbc.Driver |
4 | jdbc:mysql://[<host>][:<port>]/[<database>][?<option>[&<option>...]] |
PostgreSQL: org.postgresql.Driver |
4 | jdbc:postgresql:[//<host>[:<port>/]]<database>[?<option>[&<option>...]] |
Oracle: oracle.jdbc.driver.OracleDriver |
4 | jdbc:oracle:<driver>:@<db connection string>
where <driver> can be thin or oci8 .
example for <db connection string>: <host>:1521:<SID> with thin
<name> with oci8
|
DB2: COM.ibm.db2.jdbc.app.DB2Driver |
? | jdbc:db2:<client-name>
|
SQL-Server (6.5, 7.x and 2000): net.sourceforge.jtds.jdbc.Driver |
4 | jdbc:jtds:<type>://<server>[:<port>][/<database>][;<property>=<value>[;...]]
where <type> can be sqlserver or sybase .
|
SQL-Server, Access: org.objectweb.rmijdbc.Driver |
3 | jdbc:rmi://<rmihostname>[:<port>]/<jdbc-url> |
ODBC: sun.jdbc.odbc.JdbcOdbcDriver |
4 | jdbc:odbc:<ODBC-DB>
where <ODBC-DB> can be a DSN or Driver={Microsoft Excel Driver (*.xls)};DBQ=c:/data/month.xls;DriverID=22;READONLY=false
or Driver={Microsoft Access Driver (*.mdb)};DBQ=C:/data/month.MDB
|
JDBC-LDAP Bridge: com.octetstring.jdbcLdap.sql.JdbcLdapDriver |
4 | jdbc:ldap://<host>[:<port>]/<basedn>[?<prop>:=<val>[&<prop>:=<val>...]]
|