1 23 24 package org.infoglue.cmsinstaller; 25 import java.sql.*; 26 import java.io.*; 27 import java.util.*; 28 29 import com.mysql.jdbc.ResultSetMetaData; 30 31 public class MySQLDatabaseCommander extends DatabaseCommander 32 { 33 private final String driver = "com.mysql.jdbc.Driver"; 34 private static String charset = null; 35 private static String mysqlVersion = null; 36 37 39 public MySQLDatabaseCommander(String driverClass, String databaseHostName, String databasePortNumber, String databaseInstance, String url, String userName, String password, String infoglueDatabaseUserName, String infoglueDatabasePassword, String databaseName, String databaseSuffix, String hostName, boolean createDatabase, boolean createInitialData, boolean createAntSeekHome, boolean createOfficeStand, boolean createOfficeStand2) throws Exception 40 { 41 super(driverClass, databaseHostName, databasePortNumber, databaseInstance, url, userName, password, infoglueDatabaseUserName, infoglueDatabasePassword, databaseName, databaseSuffix, hostName, createDatabase, createInitialData, createAntSeekHome, createOfficeStand, createOfficeStand2); 42 } 44 45 public String getUrl(String hostName, String databasePortNumber, String database) 46 { 47 return "jdbc:mysql://" + databaseHostName + ":" + databasePortNumber + "/" + databaseName + ""; 48 } 49 50 public String getUnicodeUrl(String hostName, String databasePortNumber, String database) 51 { 52 return "jdbc:mysql://" + databaseHostName + ":" + databasePortNumber + "/" + databaseName + "?useUnicode=true&characterEncoding=UTF-8"; 53 } 54 55 public void setupDatabase() throws Exception 56 { 57 if(this.createDatabase) 58 createDatabase(); 59 60 if(this.createInitialData) 61 { 62 createTables(); 63 createInitialData(); 64 setupExamples(); 65 } 66 67 if(this.createDatabase) 68 createUsers(); 69 } 70 71 public void deleteDatabase() throws Exception 72 { 73 dropDatabase(); 74 dropUsers(); 75 } 76 77 78 private void createDatabase() throws Exception 79 { 80 Logger.logInfo("Setting up a new database...."); 81 issueCommand(getConnection(), "CREATE DATABASE " + databaseName + ";"); 82 } 83 84 private void createTables() throws Exception 85 { 86 String url = "jdbc:mysql://" + databaseHostName + ":" + this.databasePortNumber + "/" + databaseName + ""; 87 Connection conn = getConnection(url, this.userName, this.password); 88 89 Logger.logInfo("Setting up a new database...."); 90 91 try 92 { 93 FileInputStream fis = new FileInputStream("infoglue_core_schema.sql"); 94 StringBuffer sb = new StringBuffer (); 95 int c; 96 while((c = fis.read()) != -1) 97 { 98 char character = (char)c; 99 sb.append(character); 100 } 101 String script = sb.toString(); 102 Logger.logInfo("script:" + script); 103 104 StringTokenizer st = new StringTokenizer(script, ";"); 105 while (st.hasMoreTokens()) 106 { 107 String command = st.nextToken(); 108 issueCommand(conn, command + ";"); 110 } 111 112 } 113 catch(Exception e) 114 { 115 Logger.logInfo("Error: " + e); 116 } 117 } 118 119 private void createInitialData() throws Exception 120 { 121 String url = "jdbc:mysql://" + databaseHostName + ":" + this.databasePortNumber + "/" + databaseName + ""; 122 Connection conn = getConnection(url, this.userName, this.password); 123 124 Logger.logInfo("Setting up initial data...."); 125 126 try 127 { 128 FileInputStream fis = new FileInputStream("infoglue_initial_data.sql"); 129 StringBuffer sb = new StringBuffer (); 130 int c; 131 while((c = fis.read()) != -1) 132 { 133 char character = (char)c; 134 sb.append(character); 135 } 136 String script = sb.toString(); 137 139 String [] commands = script.split("#endquery"); 140 Logger.logInfo("Parsed " + commands.length + " commands from script"); 141 142 for(int i=0; i<commands.length; i++) 143 { 144 String command = commands[i]; 145 if(command.indexOf("SPECIAL") > -1) 146 issueSpecialCommand(conn, command.trim()); 147 else 148 issueCommand(conn, command.trim()); 149 } 150 151 } 152 catch(Exception e) 153 { 154 Logger.logInfo("Error: " + e); 155 } 156 157 } 158 159 160 public void upgradeTo1_3(Connection conn) throws Exception 161 { 162 Logger.logInfo("Upgrading to 1.3"); 163 164 try 165 { 166 FileInputStream fis = new FileInputStream("upgrade1_2_to1_3.sql"); 167 StringBuffer sb = new StringBuffer (); 168 int c; 169 while((c = fis.read()) != -1) 170 { 171 char character = (char)c; 172 sb.append(character); 173 } 174 String script = sb.toString(); 175 Logger.logInfo("script:" + script); 176 177 StringTokenizer st = new StringTokenizer(script, ";"); 178 while (st.hasMoreTokens()) 179 { 180 String command = st.nextToken(); 181 issueCommand(conn, command + ";"); 183 } 184 } 185 catch(Exception e) 186 { 187 Logger.logInfo("Error: " + e); 188 } 189 } 190 191 public void upgradeTo1_3_2(Connection conn) throws Exception 192 { 193 Logger.logInfo("Upgrading to 1.3.2"); 194 195 try 196 { 197 FileInputStream fis = new FileInputStream("upgrade1_3_to1_3_2.sql"); 198 StringBuffer sb = new StringBuffer (); 199 int c; 200 while((c = fis.read()) != -1) 201 { 202 char character = (char)c; 203 sb.append(character); 204 } 205 String script = sb.toString(); 206 Logger.logInfo("script:" + script); 207 208 StringTokenizer st = new StringTokenizer(script, ";"); 209 while (st.hasMoreTokens()) 210 { 211 String command = st.nextToken(); 212 issueCommand(conn, command + ";"); 214 } 215 } 216 catch(Exception e) 217 { 218 Logger.logInfo("Error: " + e); 219 } 220 } 221 222 public void upgradeTo2_0(Connection conn) throws Exception 223 { 224 Logger.logInfo("Upgrading to 2.0"); 225 226 try 227 { 228 FileInputStream fis = new FileInputStream("upgrade1_3_2_to2_0.sql"); 229 StringBuffer sb = new StringBuffer (); 230 int c; 231 while((c = fis.read()) != -1) 232 { 233 char character = (char)c; 234 sb.append(character); 235 } 236 String script = sb.toString(); 237 Logger.logInfo("script:" + script); 238 239 StringTokenizer st = new StringTokenizer(script, ";"); 240 while (st.hasMoreTokens()) 241 { 242 String command = st.nextToken(); 243 issueCommand(conn, command + ";"); 245 } 246 } 247 catch(Exception e) 248 { 249 Logger.logInfo("Error: " + e); 250 } 251 } 252 253 public void upgradeTo2_1(Connection conn) throws Exception 254 { 255 Logger.logInfo("Upgrading to 2.1"); 256 257 try 258 { 259 FileInputStream fis = new FileInputStream("upgrade2_0_to2_1.sql"); 260 StringBuffer sb = new StringBuffer (); 261 int c; 262 while((c = fis.read()) != -1) 263 { 264 char character = (char)c; 265 sb.append(character); 266 } 267 String script = sb.toString(); 268 Logger.logInfo("script:" + script); 269 270 StringTokenizer st = new StringTokenizer(script, ";"); 271 while (st.hasMoreTokens()) 272 { 273 String command = st.nextToken(); 274 issueCommand(conn, command + ";"); 276 } 277 } 278 catch(Exception e) 279 { 280 Logger.logInfo("Error: " + e); 281 } 282 } 283 284 public void upgradeTo2_3(Connection conn) throws Exception 285 { 286 Logger.logInfo("Upgrading to 2.3"); 287 288 try 289 { 290 FileInputStream fis = new FileInputStream("upgrade2_1_to2_3.sql"); 291 StringBuffer sb = new StringBuffer (); 292 int c; 293 while((c = fis.read()) != -1) 294 { 295 char character = (char)c; 296 sb.append(character); 297 } 298 String script = sb.toString(); 299 Logger.logInfo("script:" + script); 300 301 StringTokenizer st = new StringTokenizer(script, ";"); 302 while (st.hasMoreTokens()) 303 { 304 String command = st.nextToken(); 305 issueCommand(conn, command + ";"); 307 } 308 } 309 catch(Exception e) 310 { 311 Logger.logInfo("Error: " + e); 312 } 313 } 314 315 private void createUsers() throws Exception 316 { 317 Logger.logInfo("Setting up all users...."); 318 319 String url = "jdbc:mysql://" + databaseHostName + ":" + this.databasePortNumber + "/mysql"; 320 Connection conn = getConnection(url, this.userName, this.password); 321 322 issueCommand(conn, "GRANT ALL PRIVILEGES ON *.* TO '" + this.infoglueDatabaseUserName + "'@'%' IDENTIFIED BY '" + this.infoglueDatabasePassword + "';"); 323 issueCommand(conn, "GRANT ALL PRIVILEGES ON *.* TO '" + this.infoglueDatabaseUserName + "'@'localhost' IDENTIFIED BY '" + this.infoglueDatabasePassword + "';"); 324 issueCommand(conn, "GRANT ALL PRIVILEGES ON *.* TO '" + this.infoglueDatabaseUserName + "'@'127.0.0.1' IDENTIFIED BY '" + this.infoglueDatabasePassword + "';"); 325 issueCommand(conn, "GRANT ALL PRIVILEGES ON *.* TO '" + this.infoglueDatabaseUserName + "'@'" + this.databaseHostName + "' IDENTIFIED BY '" + this.infoglueDatabasePassword + "';"); 326 issueCommand(conn, "GRANT ALL PRIVILEGES ON *.* TO '" + this.infoglueDatabaseUserName + "'@'" + this.hostName + "' IDENTIFIED BY '" + this.infoglueDatabasePassword + "';"); 327 issueCommand(conn, "GRANT ALL PRIVILEGES ON *.* TO '" + this.infoglueDatabaseUserName + "'@'" + getHostAddress() + "' IDENTIFIED BY '" + this.infoglueDatabasePassword + "';"); 328 } 329 330 331 private void dropDatabase() throws Exception 332 { 333 Logger.logInfo("Deleting the database...."); 334 issueCommand(getConnection(), "DROP DATABASE " + databaseName + ";"); 335 } 336 337 338 private void dropUsers() throws Exception 339 { 340 Logger.logInfo("Dropping all users...."); 341 342 String url = "jdbc:mysql://" + databaseHostName + ":" + this.databasePortNumber + "/mysql"; 343 Connection conn = getConnection(url, this.userName, this.password); 344 345 issueCommand(conn, "DELETE FROM mysql.columns_priv WHERE User = '" + this.databaseSuffix + "'"); 346 issueCommand(conn, "DELETE FROM mysql.tables_priv WHERE User = '" + this.databaseSuffix + "'"); 347 issueCommand(conn, "DELETE FROM mysql.db WHERE User = '" + this.infoglueDatabaseUserName + "'"); 348 issueCommand(conn, "DELETE FROM mysql.user WHERE User = '" + this.infoglueDatabaseUserName + "'"); 349 } 350 351 354 355 private void issueCommand(Connection conn, String sql) 356 { 357 if(sql == null || sql.trim().length() == 0 || sql.trim().equalsIgnoreCase(";")) 358 return; 359 360 try 361 { 362 PreparedStatement pstmt = conn.prepareStatement(sql); 363 pstmt.execute(); 364 pstmt.close(); 365 367 } 371 catch(SQLException ex) 372 { 373 Logger.logInfo("Command failed: " + ex.getMessage()); 374 Logger.logInfo("SQL: " + sql); 375 System.err.println("SQLException: " + ex.getMessage()); 376 } 377 } 378 379 380 public void createCastorFile() throws Exception 381 { 382 StringBuffer xmlFile = new StringBuffer (); 383 384 xmlFile.append("<!DOCTYPE database PUBLIC \"-//EXOLAB/Castor JDO Configuration DTD Version 1.0//EN\" \"http://castor.codehaus.org/jdo-conf.dtd\">\n"); 385 xmlFile.append("<jdo-conf>\n"); 386 xmlFile.append("<database name=\"INFOGLUE_CMS\" engine=\"mysql\">\n"); 387 xmlFile.append("<data-source class-name=\"org.apache.commons.dbcp.BasicDataSource\">\n"); 388 xmlFile.append("<param name=\"driver-class-name\" value=\"com.mysql.jdbc.Driver\"/>\n"); 389 xmlFile.append("<param name=\"username\" value=\"" + this.infoglueDatabaseUserName + "\"/>\n"); 390 xmlFile.append("<param name=\"password\" value=\"" + this.infoglueDatabasePassword + "\"/>\n"); 391 392 if(mysqlVersion.indexOf("4.1") > -1 && charset != null) 393 { 394 xmlFile.append("<param name=\"url\" value=\"jdbc:mysql://" + databaseHostName + ":" + this.databasePortNumber + "/" + databaseName + "?autoReconnect=true\"/>\n"); 395 } 398 else 399 { 400 xmlFile.append("<param name=\"url\" value=\"jdbc:mysql://" + databaseHostName + ":" + this.databasePortNumber + "/" + databaseName + "?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8\"/>\n"); 401 } 404 405 xmlFile.append("<param name=\"max-active\" value=\"20\"/>\n"); 406 xmlFile.append("<param name=\"connection-properties\" value=\"\"/>\n"); 407 xmlFile.append("<param name=\"autoReconnect\" value=\"true\"/>\n"); 408 409 xmlFile.append("</data-source>\n"); 410 xmlFile.append("<mapping HREF=\"classes/mapping.xml\"/>\n"); 411 xmlFile.append("</database>\n"); 412 xmlFile.append("<transaction-demarcation mode=\"local\" />\n"); 413 xmlFile.append("</jdo-conf>\n"); 414 415 441 442 PrintWriter pw = new PrintWriter(new FileWriter("localConfigs/database.xml")); 443 pw.println(xmlFile.toString()); 444 pw.close(); 445 } 446 447 public void createCastorRootFile() throws Exception 448 { 449 StringBuffer xmlFile = new StringBuffer (); 450 451 xmlFile.append("<!DOCTYPE database PUBLIC \"-//EXOLAB/Castor JDO Configuration DTD Version 1.0//EN\" \"http://castor.codehaus.org/jdo-conf.dtd\">\n"); 452 xmlFile.append("<jdo-conf>\n"); 453 xmlFile.append("<database name=\"INFOGLUE_CMS\" engine=\"mysql\">\n"); 454 xmlFile.append("<data-source class-name=\"org.apache.commons.dbcp.BasicDataSource\">\n"); 455 xmlFile.append("<param name=\"driver-class-name\" value=\"com.mysql.jdbc.Driver\"/>\n"); 456 xmlFile.append("<param name=\"username\" value=\"" + this.userName + "\"/>\n"); 457 xmlFile.append("<param name=\"password\" value=\"" + this.password + "\"/>\n"); 458 459 if(mysqlVersion.indexOf("4.1") > -1 && charset != null) 460 { 461 xmlFile.append("<param name=\"url\" value=\"jdbc:mysql://" + databaseHostName + ":" + this.databasePortNumber + "/" + databaseName + "\"/>\n"); 462 } 465 else 466 { 467 xmlFile.append("<param name=\"url\" value=\"jdbc:mysql://" + databaseHostName + ":" + this.databasePortNumber + "/" + databaseName + "?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8\"/>\n"); 468 } 471 472 xmlFile.append("<param name=\"max-active\" value=\"20\"/>\n"); 473 xmlFile.append("<param name=\"connection-properties\" value=\"\"/>\n"); 474 xmlFile.append("<param name=\"autoReconnect\" value=\"true\"/>\n"); 475 476 xmlFile.append("</data-source>\n"); 477 xmlFile.append("<mapping HREF=\"classes/mapping.xml\"/>\n"); 478 xmlFile.append("</database>\n"); 479 xmlFile.append("<transaction-demarcation mode=\"local\" />\n"); 480 xmlFile.append("</jdo-conf>\n"); 481 482 508 509 PrintWriter pw = new PrintWriter(new FileWriter("localConfigs/database.xml")); 510 pw.println(xmlFile.toString()); 511 pw.close(); 512 } 513 514 public void createOSWorkflowFile() throws Exception 515 { 516 StringBuffer xmlFile = new StringBuffer (); 517 518 xmlFile.append("<osworkflow>"); 519 xmlFile.append("<persistence class=\"org.infoglue.cms.util.workflow.InfoGlueMySQLJDBCWorkflowStore\">"); 520 xmlFile.append("<property key=\"username\" value=\"" + this.infoglueDatabaseUserName + "\"/>"); 521 xmlFile.append("<property key=\"password\" value=\"" + this.infoglueDatabasePassword + "\"/>"); 522 xmlFile.append("<property key=\"driverClassName\" value=\"com.mysql.jdbc.Driver\"/>"); 523 524 if(mysqlVersion.indexOf("4.1") > -1 && charset != null) 525 { 526 xmlFile.append("<property key=\"url\" value=\"jdbc:mysql://" + databaseHostName + ":" + this.databasePortNumber + "/" + databaseName + "?autoReconnect=true\"/>"); 527 } 528 else 529 { 530 xmlFile.append("<property key=\"url\" value=\"jdbc:mysql://" + databaseHostName + ":" + this.databasePortNumber + "/" + databaseName + "?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8\"/>"); 531 } 532 533 xmlFile.append("<property key=\"entry.sequence\" value=\"SELECT max(ID)+1 FROM OS_WFENTRY\"/>"); 534 xmlFile.append("<property key=\"entry.table\" value=\"OS_WFENTRY\"/>"); 535 xmlFile.append("<property key=\"entry.id\" value=\"ID\"/>"); 536 xmlFile.append("<property key=\"entry.name\" value=\"NAME\"/>"); 537 xmlFile.append("<property key=\"entry.state\" value=\"STATE\"/>"); 538 xmlFile.append("<property key=\"step.sequence\" value=\"SELECT max(ID) FROM OS_CURRENTSTEP\"/>"); 539 xmlFile.append("<property key=\"history.table\" value=\"OS_HISTORYSTEP\"/>"); 540 xmlFile.append("<property key=\"current.table\" value=\"OS_CURRENTSTEP\"/>"); 541 xmlFile.append("<property key=\"historyPrev.table\" value=\"OS_HISTORYSTEP_PREV\"/>"); 542 xmlFile.append("<property key=\"currentPrev.table\" value=\"OS_CURRENTSTEP_PREV\"/>"); 543 xmlFile.append("<property key=\"step.id\" value=\"ID\"/>"); 544 xmlFile.append("<property key=\"step.entryId\" value=\"ENTRY_ID\"/>"); 545 xmlFile.append("<property key=\"step.stepId\" value=\"STEP_ID\"/>"); 546 xmlFile.append("<property key=\"step.actionId\" value=\"ACTION_ID\"/>"); 547 xmlFile.append("<property key=\"step.owner\" value=\"OWNER\"/>"); 548 xmlFile.append("<property key=\"step.caller\" value=\"CALLER\"/>"); 549 xmlFile.append("<property key=\"step.startDate\" value=\"START_DATE\"/>"); 550 xmlFile.append("<property key=\"step.finishDate\" value=\"FINISH_DATE\"/>"); 551 xmlFile.append("<property key=\"step.dueDate\" value=\"DUE_DATE\"/>"); 552 xmlFile.append("<property key=\"step.status\" value=\"STATUS\"/>"); 553 xmlFile.append("<property key=\"step.previousId\" value=\"PREVIOUS_ID\"/>"); 554 xmlFile.append("<property key=\"step.sequence.increment\" value=\"INSERT INTO OS_STEPIDS (ID) values (null)\"/>"); 555 xmlFile.append("<property key=\"step.sequence.retrieve\" value=\"SELECT max(ID) FROM OS_STEPIDS\"/>"); 556 xmlFile.append("</persistence>"); 557 558 xmlFile.append("<factory class=\"com.opensymphony.workflow.loader.XMLWorkflowFactory\">"); 559 xmlFile.append("<property key=\"resource\" value=\"workflows.xml\" />"); 560 xmlFile.append("</factory>"); 561 562 xmlFile.append("</osworkflow>"); 563 564 PrintWriter pw = new PrintWriter(new FileWriter("localConfigs/osworkflow.xml")); 565 pw.println(xmlFile.toString()); 566 pw.close(); 567 } 568 569 public void createOSPropertiesFile() throws Exception 570 { 571 StringBuffer xmlFile = new StringBuffer (); 572 573 xmlFile.append("<propertysets>"); 574 xmlFile.append("<propertyset name=\"aggregate\" class=\"com.opensymphony.module.propertyset.aggregate.AggregatePropertySet\"/>"); 575 xmlFile.append("<propertyset name=\"cached\" class=\"com.opensymphony.module.propertyset.cached.CachingPropertySet\"/>"); 576 xmlFile.append("<propertyset name=\"jdbc\" class=\"org.infoglue.cms.util.workflow.InfoGlueJDBCPropertySet\">"); 577 xmlFile.append("<arg name=\"username\" value=\"" + this.infoglueDatabaseUserName + "\"/>"); 578 xmlFile.append("<arg name=\"password\" value=\"" + this.infoglueDatabasePassword + "\"/>"); 579 xmlFile.append("<arg name=\"driverClassName\" value=\"com.mysql.jdbc.Driver\"/>"); 580 581 if(mysqlVersion.indexOf("4.1") > -1 && charset != null) 582 { 583 xmlFile.append("<arg name=\"url\" value=\"jdbc:mysql://" + databaseHostName + ":" + this.databasePortNumber + "/" + databaseName + "?autoReconnect=true\"/>"); 584 } 585 else 586 { 587 xmlFile.append("<arg name=\"url\" value=\"jdbc:mysql://" + databaseHostName + ":" + this.databasePortNumber + "/" + databaseName + "?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8\"/>"); 588 } 589 590 xmlFile.append("<arg name=\"table.name\" value=\"OS_PROPERTYENTRY\"/>"); 591 601 xmlFile.append("<arg name=\"col.globalKey\" value=\"entity_name\"/>"); 602 xmlFile.append("<arg name=\"col.entityId\" value=\"entity_id\"/>"); 603 xmlFile.append("<arg name=\"col.itemKey\" value=\"entity_key\"/>"); 604 xmlFile.append("<arg name=\"col.itemType\" value=\"key_type\"/>"); 605 xmlFile.append("<arg name=\"col.booleanVal\" value=\"boolean_val\"/>"); 606 xmlFile.append("<arg name=\"col.string\" value=\"string_val\"/>"); 607 xmlFile.append("<arg name=\"col.date\" value=\"date_val\"/>"); 608 xmlFile.append("<arg name=\"col.data\" value=\"data_val\"/>"); 609 xmlFile.append("<arg name=\"col.float\" value=\"double_val\"/>"); 610 xmlFile.append("<arg name=\"col.number\" value=\"int_val\"/>"); 611 612 xmlFile.append("</propertyset>"); 613 xmlFile.append("<propertyset name=\"ejb\" class=\"com.opensymphony.module.propertyset.ejb.EJBPropertySet\"/>"); 614 xmlFile.append("<propertyset name=\"javabeans\" class=\"com.opensymphony.module.propertyset.javabeans.BeanIntrospectorPropertySet\"/>"); 615 xmlFile.append("<propertyset name=\"map\" class=\"com.opensymphony.module.propertyset.map.MapPropertySet\"/>"); 616 xmlFile.append("<propertyset name=\"memory\" class=\"com.opensymphony.module.propertyset.memory.MemoryPropertySet\"/>"); 617 xmlFile.append("<propertyset name=\"serializable\" class=\"com.opensymphony.module.propertyset.memory.SerializablePropertySet\"/>"); 618 xmlFile.append("<propertyset name=\"ofbiz\" class=\"com.opensymphony.module.propertyset.ofbiz.OFBizPropertySet\"/>"); 619 xmlFile.append("<propertyset name=\"hibernate\" class=\"org.infoglue.cms.util.workflow.hibernate.InfoGlueHibernatePropertySet\"/>"); 620 xmlFile.append("<propertyset name=\"xml\" class=\"com.opensymphony.module.propertyset.xml.XMLPropertySet\"/>"); 621 xmlFile.append("</propertysets>"); 622 623 PrintWriter pw = new PrintWriter(new FileWriter("localConfigs/propertyset.xml")); 624 pw.println(xmlFile.toString()); 625 pw.close(); 626 } 627 628 public void testSetupDummyDatabase() throws Exception 629 { 630 PreparedStatement pstmt = getConnection().prepareStatement("CREATE DATABASE infoglueDummy;"); 631 pstmt.execute(); 632 pstmt.close(); 633 634 pstmt = getConnection().prepareStatement("CREATE TABLE infoglueDummy.cmTest(test varchar(200) NOT NULL) TYPE=MyISAM;"); 635 pstmt.execute(); 636 pstmt.close(); 637 638 pstmt = getConnection().prepareStatement("INSERT INTO infoglueDummy.cmTest(test) values ('Test');"); 639 pstmt.execute(); 640 pstmt.close(); 641 642 String sql = "SELECT * from infoglueDummy.cmTest;"; 643 PreparedStatement ps = getConnection().prepareStatement(sql); 644 ps.execute(); 645 ResultSet rs = ps.getResultSet(); 646 mysqlVersion = ps.getConnection().getMetaData().getDatabaseMajorVersion() + "." + ps.getConnection().getMetaData().getDatabaseMinorVersion(); 647 charset = ((ResultSetMetaData)rs.getMetaData()).getColumnCharacterSet(1); 648 System.out.println("mysqlVersion:" + mysqlVersion); 649 System.out.println("Encoding:" + charset); 650 651 pstmt = getConnection().prepareStatement("DROP DATABASE infoglueDummy;"); 652 pstmt.execute(); 653 pstmt.close(); 654 } 655 656 657 public void testConnectDatabase() throws Exception 658 { 659 System.out.println("testConnectDatabase"); 660 661 Connection conn = getConnection(getUrl(this.databaseHostName, this.databasePortNumber, this.databaseName + this.databaseSuffix), this.infoglueDatabaseUserName, this.infoglueDatabasePassword); 662 664 System.out.println("conn:" + conn); 665 666 String sql = "SELECT * from cmContent;"; 667 PreparedStatement ps = conn.prepareStatement(sql); 668 ps.execute(); 669 ResultSet rs = ps.getResultSet(); 670 mysqlVersion = ps.getConnection().getMetaData().getDatabaseMajorVersion() + "." + ps.getConnection().getMetaData().getDatabaseMinorVersion(); 671 charset = ((ResultSetMetaData)rs.getMetaData()).getColumnCharacterSet(1); 672 System.out.println("mysqlVersion:" + mysqlVersion); 673 System.out.println("Encoding:" + charset); 674 } 675 676 679 protected void issueSpecialBlobCommand(Connection conn, String sql) 680 { 681 683 } 684 685 688 public String getDriver() 689 { 690 return driver; 691 } 692 693 public static String getCharset() 694 { 695 return charset; 696 } 697 698 public static String getMysqlVersion() 699 { 700 return mysqlVersion; 701 } 702 703 public String getDatabaseVendor() throws Exception 704 { 705 return "MySQL"; 706 } 707 708 } | Popular Tags |