This commit is contained in:
Francesco Mangiacrapa 2013-11-11 15:01:10 +00:00
parent 3285020ed8
commit 46e4be0a67
1 changed files with 27 additions and 8 deletions

View File

@ -12,8 +12,6 @@ import java.sql.Statement;
import java.util.HashMap;
import java.util.Map;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
@ -35,6 +33,7 @@ public class DBTester {
public static void main(String[] a) throws Exception {
Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection("jdbc:h2:/home/francesco-mangiacrapa/Portal-Bundle2.2/tomcat-6.0.29/persistence/h2dbspecies/h2testusergcubedevsec;create=true", "","");
// add application code here
@ -61,20 +60,40 @@ public class DBTester {
System.out.println("\n\n");
}
conn.close();
// testJdbcDataSource();
}
public static void getConnection() throws NamingException {
public static void testJdbcDataSource() throws NamingException {
JdbcDataSource ds = new JdbcDataSource();
ds.setURL("jdbc:h2:/home/francesco-mangiacrapa/Portal-Bundle2.2/tomcat-6.0.29/persistence/h2dbspecies/h2testusergcubedevsec;create=true");
Context ctx = new InitialContext();
ctx.bind("jdbc/h2testusergcubedevsec", ds);
// Context ctx = new InitialContext();
// ctx.bind("jdbc/h2testusergcubedevsec/TaxonomyRow.class", ds);
try {
Connection conn = ds.getConnection();
conn.createStatement().execute("Select * from TaxonomyJob");
Connection conn = ds.getConnection();
ResultSet rs = conn.createStatement().executeQuery("select * from TaxonomyRow");
ResultSetMetaData meta = rs.getMetaData();
int columnCount = meta.getColumnCount();
while (rs.next())
{
System.out.println("New row");
for (int i = 1; i <= columnCount; i++) {
// System.out.println("ColumName: "+ meta.getColumnName(i));
System.out.println("ColumLabel: "+meta.getColumnLabel(i));
System.out.println(rs.getString(meta.getColumnLabel(i)));
}
System.out.println("\n\n");
}
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();