1 9 package org.jboss.portal.test.core; 10 11 import java.io.FileInputStream ; 12 import java.sql.Connection ; 13 import java.sql.DriverManager ; 14 import java.sql.SQLException ; 15 import java.sql.Statement ; 16 17 import org.dbunit.database.DatabaseConnection; 18 import org.dbunit.database.IDatabaseConnection; 19 import org.dbunit.dataset.IDataSet; 20 import org.dbunit.dataset.xml.FlatXmlDataSet; 21 22 26 public class Utils 27 { 28 29 private static String url = "jdbc:mysql://localhost:3306/jbossportal?useServerPrepStmts=false"; 30 private static String username = "portal"; 31 private static String password = "portalpassword"; 32 33 public static IDataSet getDataSet(String file) throws Exception 34 { 35 return new FlatXmlDataSet(new FileInputStream (file)); 36 } 37 38 public static IDatabaseConnection getConnection() throws Exception 39 { 40 Class driverClass = Class.forName("org.gjt.mm.mysql.Driver"); 41 Connection jdbcConnection = DriverManager.getConnection( 42 url, username, password); 43 return new DatabaseConnection(jdbcConnection); 44 } 45 46 public static void resetAutoIncrement() throws SQLException { 47 Connection jdbcConnection = DriverManager.getConnection( 48 url, username, password); 49 Statement stmt = jdbcConnection.createStatement(); 50 stmt.execute("alter table jbp_roles auto_increment=1"); 51 } 52 } 53 | Popular Tags |