Code written in Java
File metadataDir = new File("svalka");
File screenshotsDir = new File(metadataDir, "tmpScreenshots");
JPanel panel = new JPanel();
panel.putClientProperty(SwingUtilities2.AA_TEXT_PROPERTY_KEY, new Boolean( true ) );
A simple program to test the various JDBC drivers.
import java.sql.*;
public class TestJdbc {
static String sql = "select * from test_table where column1 = ?";
static String userId = "userid";
static String password = "password";
static String dbServer = "dbserver";
static String dbName = "database";
public static void main(String[] args) throws Exception {
testMSDriver();
}
private static void testMSDriver() throws Exception {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://"+ dbServer +";SendStringParametersAsUnicode=false;dataSourceName=SQL2000JDBC;databaseName="+ dbName +";serverName="+ dbServer +";selectMethod=cursor", userId, password);
long start = System.currentTimeMillis();
PreparedStatement stmt = conn.prepareStatement(sql);
stmt.setString(1, "string1");
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
// System.out.println("Result: " + rs.getString(1));
}
conn.close();
System.out.println("Elapsed time for MS driver: " +
(System.currentTimeMillis() - start));
}
}
// Creates a HelloWorld using Swing. The code uses the class JOptionPane to create
// a Input dialog that read a value, then shows a message dialog that show a message
// with the value.
public class HelloJavaJOP {
/**
* @param args
*/
public static void main(String[] args) {
String nome = JOptionPane.showInputDialog("Digite seu nome");
String mensagem = null;
if (nome != null && !nome.equals("")) {
mensagem = "Bem-vindo ao mundo Java, " + nome + "!";
} else {
mensagem = "Bem-vindo ao mundo Java, USUARIO";
}
JOptionPane.showMessageDialog(null, mensagem);
}
}
Struts will mangle data that is received from form submissions, this is because as the data comes in most browsers don�??t set the content type.
to stop struts mangling the data you need to set the content type with a filter before it gets as far as the struts layer.
This is a simple class for writing XML DOM Documents to a file using Apache Xerces
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.xml.serialize.OutputFormat;
import org.apache.xml.serialize.XMLSerializer;
import org.w3c.dom.Document;
public class XMLWriter
{
public static void saveToXMLFile (final String sFilename, final Document d)
{
try
{
final OutputFormat of = new OutputFormat ();
of.setPreserveSpace (false);
of.setLineWidth (0);
of.setIndent (2);
final FileOutputStream os = new FileOutputStream (sFilename);
final XMLSerializer xs = new XMLSerializer (os, of);
xs.asDOMSerializer ().serialize (d);
os.close ();
}
catch (FileNotFoundException e)
{
e.printStackTrace ();
}
catch (IOException e)
{
e.printStackTrace ();
}
}
}