List of usage examples for java.sql DriverManager registerDriver
public static void registerDriver(java.sql.Driver driver) throws SQLException
From source file:Action.UserExamQuizAction.java
@Override public String execute() throws SQLException { this.userexam = (String) session.get("exam"); DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system", "system"); Statement stmt = (Statement) con.createStatement(); String str;//from ww w . j a v a 2 s . co m ResultSet rs; str = "select * from questions where subject ='" + this.userexam + "'"; rs = stmt.executeQuery(str); rs.next(); rs.getString(1); this.ques1 = "Q1: " + rs.getString(2); list1 = new LinkedList<String>(); this.right1 = rs.getString(3); session.put("right1", right1); list1.add(rs.getString(4)); list1.add(rs.getString(5)); list1.add(right1); list1.add(rs.getString(6)); rs.next(); rs.getString(1); this.ques2 = "Q2: " + rs.getString(2); list2 = new LinkedList<String>(); this.right2 = rs.getString(3); session.put("right2", right2); list2.add(rs.getString(4)); list2.add(rs.getString(5)); list2.add(rs.getString(6)); list2.add(right2); rs.next(); rs.getString(1); this.ques3 = "Q3: " + rs.getString(2); list3 = new LinkedList<String>(); this.right3 = rs.getString(3); session.put("right3", right3); list3.add(rs.getString(4)); list3.add(right3); list3.add(rs.getString(5)); list3.add(rs.getString(6)); rs.next(); rs.getString(1); this.ques4 = "Q4: " + rs.getString(2); list4 = new LinkedList<String>(); this.right4 = rs.getString(3); session.put("right4", right4); list4.add(rs.getString(4)); list4.add(rs.getString(5)); list4.add(rs.getString(6)); list4.add(right4); rs.next(); rs.getString(1); this.ques5 = "Q5: " + rs.getString(2); list5 = new LinkedList<String>(); this.right5 = rs.getString(3); session.put("right5", right5); list5.add(rs.getString(4)); list5.add(rs.getString(5)); list5.add(right5); list5.add(rs.getString(6)); return SUCCESS; }
From source file:gsn.vsensor.TestStreamExporterVirtualSensor.java
public void testLogStatementIntoMySQLDB() { StreamExporterVirtualSensor vs = new StreamExporterVirtualSensor(); // configure parameters ArrayList<KeyValue> params = new ArrayList<KeyValue>(); params.add(new KeyValueImp(StreamExporterVirtualSensor.PARAM_URL, url)); params.add(new KeyValueImp(StreamExporterVirtualSensor.PARAM_USER, user)); params.add(new KeyValueImp(StreamExporterVirtualSensor.PARAM_PASSWD, passwd)); config.setMainClassInitialParams(params); vs.setVirtualSensorConfiguration(config); vs.initialize();// www . j av a 2 s . c o m // configure datastream Vector<DataField> fieldTypes = new Vector<DataField>(); Object[] data = null; for (String type : DataTypes.TYPE_NAMES) fieldTypes.add(new DataField(type, type, type)); int i = 0; for (Object value : DataTypes.TYPE_SAMPLE_VALUES) data[i++] = value; long timeStamp = new Date().getTime(); StreamElement streamElement = new StreamElement(fieldTypes.toArray(new DataField[] {}), (Serializable[]) data, timeStamp); // give datastream to vs vs.dataAvailable(streamName, streamElement); // clean up and control boolean result = true; try { DriverManager.registerDriver(new com.mysql.jdbc.Driver()); Connection connection = DriverManager.getConnection(url, user, passwd); Statement statement = connection.createStatement(); statement.execute("SELECT * FROM " + streamName); System.out.println("result" + result); result = statement.getResultSet().last(); System.out.println("result" + result); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); result = false; } assertTrue(result); }
From source file:org.pentaho.platform.dataaccess.datasource.wizard.service.impl.utils.DatasourceInMemoryServiceHelper.java
/** * NOTE: caller is responsible for closing connection * * @param connectionName/*from www .j a v a2 s . co m*/ * @return * @throws DatasourceServiceException */ public static java.sql.Connection getDataSourceConnection(String connectionName) throws DatasourceServiceException { IDatabaseConnection connection = null; try { ConnectionServiceImpl service = new ConnectionServiceImpl(); connection = service.getConnectionByName(connectionName); } catch (ConnectionServiceException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } java.sql.Connection conn = null; DatabaseDialectService dialectService = new DatabaseDialectService(); IDatabaseDialect dialect = dialectService.getDialect(connection); String driverClass = null; if (connection.getDatabaseType().getShortName().equals("GENERIC")) { driverClass = connection.getAttributes().get(GenericDatabaseDialect.ATTRIBUTE_CUSTOM_DRIVER_CLASS); } else { driverClass = dialect.getNativeDriver(); } if (StringUtils.isEmpty(driverClass)) { logger.error(Messages .getErrorString("DatasourceInMemoryServiceHelper.ERROR_0001_CONNECTION_ATTEMPT_FAILED")); //$NON-NLS-1$ throw new DatasourceServiceException(Messages .getErrorString("DatasourceInMemoryServiceHelper.ERROR_0001_CONNECTION_ATTEMPT_FAILED")); //$NON-NLS-1$ } Class<?> driverC = null; try { driverC = Class.forName(driverClass); } catch (ClassNotFoundException e) { logger.error(Messages.getErrorString( "DatasourceInMemoryServiceHelper.ERROR_0002_DRIVER_NOT_FOUND_IN_CLASSPATH", driverClass), e); //$NON-NLS-1$ throw new DatasourceServiceException(Messages .getErrorString("DatasourceInMemoryServiceHelper.ERROR_0002_DRIVER_NOT_FOUND_IN_CLASSPATH"), e); //$NON-NLS-1$ } if (!Driver.class.isAssignableFrom(driverC)) { logger.error(Messages.getErrorString( "DatasourceInMemoryServiceHelper.ERROR_0002_DRIVER_NOT_FOUND_IN_CLASSPATH", driverClass)); //$NON-NLS-1$ throw new DatasourceServiceException(Messages.getErrorString( "DatasourceInMemoryServiceHelper.ERROR_0002_DRIVER_NOT_FOUND_IN_CLASSPATH", driverClass)); //$NON-NLS-1$ } Driver driver = null; try { driver = driverC.asSubclass(Driver.class).newInstance(); } catch (InstantiationException e) { logger.error(Messages.getErrorString( "DatasourceInMemoryServiceHelper.ERROR_0003_UNABLE_TO_INSTANCE_DRIVER", driverClass), e); //$NON-NLS-1$ throw new DatasourceServiceException( Messages.getErrorString("DatasourceInMemoryServiceHelper.ERROR_0003_UNABLE_TO_INSTANCE_DRIVER"), e); //$NON-NLS-1$ } catch (IllegalAccessException e) { logger.error(Messages.getErrorString( "DatasourceInMemoryServiceHelper.ERROR_0003_UNABLE_TO_INSTANCE_DRIVER", driverClass), e); //$NON-NLS-1$ throw new DatasourceServiceException( Messages.getErrorString("DatasourceInMemoryServiceHelper.ERROR_0003_UNABLE_TO_INSTANCE_DRIVER"), e); //$NON-NLS-1$ } try { DriverManager.registerDriver(driver); conn = DriverManager.getConnection(dialect.getURLWithExtraOptions(connection), connection.getUsername(), connection.getPassword()); return conn; } catch (SQLException e) { logger.error(Messages.getErrorString("DatasourceInMemoryServiceHelper.ERROR_0004_UNABLE_TO_CONNECT"), e); //$NON-NLS-1$ throw new DatasourceServiceException( Messages.getErrorString("DatasourceInMemoryServiceHelper.ERROR_0004_UNABLE_TO_CONNECT"), e); //$NON-NLS-1$ } catch (DatabaseDialectException e) { throw new DatasourceServiceException( Messages.getErrorString("DatasourceInMemoryServiceHelper.ERROR_0004_UNABLE_TO_CONNECT"), e); //$NON-NLS-1$ } }
From source file:com.alibaba.druid.benckmark.pool.PoolPerformanceTest.java
@Before public void setUp() throws Exception { DriverManager.registerDriver(TestDriver.instance); user = "dragoon25"; password = "dragoon25"; // jdbcUrl = "jdbc:h2:mem:"; // driverClass = "org.h2.Driver"; jdbcUrl = "jdbc:test:case1:"; driverClass = "com.alibaba.druid.benckmark.pool.PoolPerformanceTest$TestDriver"; physicalConnStat.set(0);//from ww w . j a va 2 s .com }
From source file:com.nilostep.xlsql.database.xlInstance.java
/** * get java.sql.Connection to engine// ww w. jav a 2s. c o m * * @return Connection */ public Connection connect() { Connection ret = null; try { String classname = this.getDriver(); logger.info("=> loading driver: " + classname); Driver d = (Driver) Class.forName(classname).newInstance(); logger.info("OK. " + classname + " loaded."); logger.info("=> registering driver: " + classname); DriverManager.registerDriver(new xlEngineDriver(d)); logger.info("OK. "); String url = getUrl(); String user = getUser(); String password = getPassword(); logger.info("=> connecting to: " + user + "/" + password + "@" + url); ret = DriverManager.getConnection(url, user, password); } catch (ClassNotFoundException nfe) { logger.warning("Driver not found. Classpath set?"); } catch (InstantiationException ie) { logger.warning("Error while instantiating driver class. ..?"); } catch (IllegalAccessException iae) { logger.warning("Illegal access. Have sources been modified?"); } catch (SQLException sqe) { logger.warning("java.sql package reports: '" + sqe.getMessage() + ":" + sqe.getSQLState() + "' ..?"); } return ret; }
From source file:org.sakaiproject.hikaricp.jdbc.pool.SakaiBasicDataSource.java
/** * @exception SQLException/*from w ww. j a v a 2 s .c om*/ * if the object pool cannot be created. */ protected void init() throws SQLException { M_log.info("init()"); //Do some quick validation if (getUsername() == null) { M_log.warn("Hikari DataSource configured without a 'username'"); } if (getPassword() == null) { M_log.warn("Hikari DataSource configured without a 'password'"); } //For backward compatibility with old methods if (url != null && !"".equals(url)) { super.setJdbcUrl(url); //This seems to also be required as HikariCP isn't registering this class if it's specified and it gives an error if (driverClassName != null) { super.setDriverClassName(driverClassName); try { Class driverClass; driverClass = Class.forName(driverClassName); DriverManager.registerDriver((Driver) driverClass.newInstance()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { // TODO Auto-generated catch block String message = "driverClass not specified, might not be able to load the driver'"; M_log.info(message, e); } } } super.setTransactionIsolation(isolationLevel); //Validate the class to verify it loaded try { super.validate(); } catch (Exception t) { String message = "Cannot load JDBC driver class '" + driverClassName + "'"; M_log.error(message, t); throw new SQLException(message, t); } }
From source file:org.apache.jena.jdbc.remote.RemoteEndpointDriver.java
/** * Registers the driver with the JDBC {@link DriverManager} * //from w w w . j ava 2 s. c o m * @throws SQLException * Thrown if the driver cannot be registered */ public static synchronized void register() throws SQLException { DriverManager.registerDriver(new RemoteEndpointDriver()); }
From source file:de.freese.base.persistence.jdbc.driver.TestLoggingJdbcDriver.java
/** * @throws Exception Falls was schief geht. *//*from www . j a v a 2 s. c om*/ @BeforeClass public static void beforeClass() throws Exception { // Backend-Treiber: Wird durch App-Server oder Datasource erledigt. // Class.forName(DRIVER, true, ClassUtils.getDefaultClassLoader()); // Proxy-Treiber, bei Web-Anwendungen durch ServletContextListener erledigen oder durch Spring. DriverManager.registerDriver(new LoggingJdbcDriver()); LoggingJdbcDriver.addDefaultLogMethods(); // (System.setProperty("org.slf4j.simpleLogger.log.de.freese.base.persistence.jdbc.driver.LoggingJdbcDriver", "INFO"); }
From source file:uk.chromis.pos.forms.JRootApp.java
private void runRepair() throws SQLException { // this routine checks for a repair script in the folder if it is found then it will execute it String s = new String(); StringBuffer sb = new StringBuffer(); db_user = (AppConfig.getInstance().getProperty("db.user")); db_url = (AppConfig.getInstance().getProperty("db.URL")); db_password = (AppConfig.getInstance().getProperty("db.password")); if (db_user != null && db_password != null && db_password.startsWith("crypt:")) { AltEncrypter cypher = new AltEncrypter("cypherkey" + db_user); db_password = cypher.decrypt(db_password.substring(6)); }// w w w . j a v a 2s. c om FileReader fr; File file; try { file = new File(System.getProperty("user.dir") + "/repair.sql"); fr = new FileReader(file); } catch (FileNotFoundException ex) { return; } try { ClassLoader cloader = new URLClassLoader( new URL[] { new File(AppConfig.getInstance().getProperty("db.driverlib")).toURI().toURL() }); DriverManager.registerDriver(new DriverWrapper((Driver) Class .forName(AppConfig.getInstance().getProperty("db.driver"), true, cloader).newInstance())); Class.forName(AppConfig.getInstance().getProperty("db.driver")); con = DriverManager.getConnection(db_url, db_user, db_password); stmt = (Statement) con.createStatement(); BufferedReader br = new BufferedReader(fr); while ((s = br.readLine()) != null) { sb.append(s); } br.close(); String[] inst = sb.toString().split(";"); for (int i = 0; i < inst.length; i++) { if (!inst[i].trim().equals("")) { stmt.executeUpdate(inst[i]); System.out.println(">>" + inst[i]); } } file.delete(); } catch (Exception e) { System.out.println("*** Error : " + e.toString()); System.out.println("*** "); System.out.println("*** Error : "); e.printStackTrace(); System.out.println("################################################"); System.out.println(sb.toString()); } finally { con.close(); } }
From source file:com.amitycoin.enterprisetool.diagramInputServlet.java
@Override @SuppressWarnings({ "null", "ValueOfIncrementOrDecrementUsed", "UnusedAssignment" }) protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String filePath;//from www . j a v a 2s .c o m String docids; String userid; String a[][]; a = new String[200][200]; // database connection settings String dbURL = "jdbc:mysql://localhost:3306/enterprisedb"; String dbUser = "root"; String dbPass = "sandy"; @SuppressWarnings("UnusedAssignment") Connection conn = null; // connection to the database userid = (String) request.getAttribute("uidM"); String fname = (String) request.getAttribute("fnameM"); int docid = (Integer) request.getAttribute("docidM"); docids = "" + docid; String pathToWeb; pathToWeb = getServletContext().getRealPath(File.separator); System.out.println("pathtoweb:\t" + pathToWeb); filePath = pathToWeb + "readFiles\\"; filePath = filePath + docids + userid + fname; //+.xls File myFile = new File(filePath); //boolean newExcel; //boolean oldExcel; String ext = FilenameUtils.getExtension(filePath); System.out.println("Extension: " + ext); FileInputStream fis = new FileInputStream(myFile); Workbook wb = null; if ("xls".equals(ext)) { // Finds the workbook instance for the file wb = new HSSFWorkbook(fis); } else if ("xlsx".equals(ext)) { wb = new XSSFWorkbook(fis); } @SuppressWarnings("null") Sheet mySheet; mySheet = wb.getSheetAt(0); // Get iterator to all the rows in current sheet Iterator<Row> rowIterator = mySheet.iterator(); @SuppressWarnings("UnusedAssignment") int rowct = 0, colct = 0, colit = 0, ci = 0, ri = 0; // Traversing over each row of XLSX file while (rowIterator.hasNext()) { ri++; System.out.println("\nRi:\t" + ri); //Iterate over Rows Row row = rowIterator.next(); if (1 == rowct) { colct = colit; } // For each row, iterate through each columns Iterator<Cell> cellIterator = row.cellIterator(); ci = 0; while (cellIterator.hasNext()) { ci++; System.out.println("\nCi:\t" + ci); //Iterate over Columns Cell cell = cellIterator.next(); switch (cell.getCellType()) { case Cell.CELL_TYPE_STRING: System.out.print(cell.getStringCellValue() + "\t"); a[ri][ci] = cell.getStringCellValue(); break; case Cell.CELL_TYPE_NUMERIC: System.out.print(cell.getNumericCellValue() + "\t"); double temp = cell.getNumericCellValue(); String dblValue = "" + temp; a[ri][ci] = dblValue; break; case Cell.CELL_TYPE_BOOLEAN: System.out.print(cell.getBooleanCellValue() + "\t"); String tmp = "" + cell.getBooleanCellValue(); a[ri][ci] = tmp; break; default: } colit++; } //rowit++; rowct++; //increase row count } System.out.println("Row Count:\t" + rowct); System.out.println("Column Count:\t" + colct); for (int i = 1; i <= rowct; i++) { for (int j = 1; j <= colct; j++) { System.out.println("a[" + i + "][" + j + "]=" + a[i][j] + "\n"); } } try { DriverManager.registerDriver(new com.mysql.jdbc.Driver()); conn = DriverManager.getConnection(dbURL, dbUser, dbPass); String append = "?, ?"; String quest = ", ?"; for (int j = 1; j <= colct; j++) { append += quest; } String crsql; String cappend = "`uid`,`doc_id`"; for (int j = 1; j <= colct; j++) { cappend = cappend + ",`" + j + "`"; } crsql = "CREATE TABLE IF NOT EXISTS `data" + userid + docid + "` (\n" + "`row_id` INT(11) NOT NULL AUTO_INCREMENT,\n" + "`uid` VARCHAR(50) NOT NULL,\n" + "`doc_id` INT(11) NOT NULL"; System.out.println(crsql); for (int j = 1; j <= colct; j++) { System.out.println("j:\t" + (j)); crsql = crsql + ",\n`" + (j) + "` VARCHAR(50)"; } crsql += ",\nPRIMARY KEY (`row_id`)\n)"; System.out.println(crsql); PreparedStatement cstmt = conn.prepareStatement(crsql); int c = cstmt.executeUpdate(); String sql = "INSERT INTO data" + userid + docid + "(" + cappend + ")" + " values (" + append + ")"; System.out.println("Append=\t" + append); PreparedStatement statement = conn.prepareStatement(sql); statement.setString(1, userid); statement.setInt(2, docid); for (int i = 1; i <= rowct; i++) { for (int j = 1; j <= (colct); j++) { statement.setString(j + 2, a[i][j]); System.out.println("j=" + (j) + "\ta[" + i + "][" + (j) + "]=" + a[i][j] + "\n"); } System.out.println("\n"); System.out.println("\nstatement:\t" + statement); int res = statement.executeUpdate(); } } catch (SQLException ex) { Logger.getLogger(diagramInputServlet.class.getName()).log(Level.SEVERE, null, ex); } for (int i = 1; i <= rowct; i++) { for (int j = 1; j <= colct; j++) { System.out.println("a[" + i + "][" + j + "]=" + a[i][j] + "\n"); } } System.out.println("Rowct:\t" + rowct + "\nColct:\t" + colct); @SuppressWarnings("UseOfObsoleteCollectionType") Hashtable<String, Object> style = new Hashtable<String, Object>(); style.put(mxConstants.STYLE_FILLCOLOR, mxUtils.getHexColorString(Color.WHITE)); style.put(mxConstants.STYLE_STROKEWIDTH, 1.5); style.put(mxConstants.STYLE_STROKECOLOR, mxUtils.getHexColorString(new Color(0, 0, 170))); style.put(mxConstants.STYLE_SHAPE, mxConstants.SHAPE_ELLIPSE); style.put(mxConstants.STYLE_PERIMETER, mxConstants.PERIMETER_ELLIPSE); graph = new mxGraph(); mxStylesheet stylesheet = graph.getStylesheet(); stylesheet.putCellStyle("process", createProcessStyle()); stylesheet.putCellStyle("object", createObjectStyle()); stylesheet.putCellStyle("state", createStateStyle()); stylesheet.putCellStyle("agent", createAgentLinkStyle()); fr = new JFrame("Enterprise Architecture Diagram"); fr.setSize(2000, 2000); graph.setMinimumGraphSize(new mxRectangle(0, 0, 1000, 1500)); graph.setMaximumGraphBounds(new mxRectangle(0, 0, 2000, 2000)); graph.setMinimumGraphSize(new mxRectangle(0, 0, 1000, 1000)); double rech1 = 200; double rech2 = 200; double rech3 = 170; double rech3e = 180; double rech4 = 120; Object defaultParent = graph.getDefaultParent(); graph.setConstrainChildren(true); graph.setExtendParents(true); graph.setExtendParentsOnAdd(true); graph.setDefaultOverlap(0); graph.setCellsMovable(true); // Moving cells in the graph. Note that an edge is also a cell. graph.setCellsEditable(true); graph.setCellsResizable(true); // Inhibit cell re-sizing. graph.getModel().beginUpdate(); Object[] obj = new Object[100]; int k = 1; for (int i = 2; i <= rowct; i++) { for (int j = 1; j <= 2; j++) { obj[k] = a[i][j]; k++; } } //print debug info for (int l = 1; l <= (rowct * 2) - 2; l++) { System.out.println("obj[" + l + "]:\t" + obj[l]); } List<Object> list = new ArrayList<Object>(); for (Object val : obj) { if (!list.contains(val)) { list.add(val); } } list.remove(null); list.toArray(new Object[0]); System.out.println("list:" + list); Object[] array = new Object[list.size()]; list.toArray(array); // fill the array System.out.println("Array:\t" + Arrays.toString(array)); Object[] gArray = new Object[array.length]; String[] sArray = new String[array.length]; for (int i = 0; i < array.length; i++) { sArray[i] = array[i].toString(); if (sArray[i].contains("Database") || sArray[i].contains("Server") || sArray[i].contains("DATABASE") || sArray[i].contains("SERVER") || sArray[i].contains("DB")) { System.out.println("Object type"); gArray[i] = graph.insertVertex(defaultParent, null, sArray[i], rech1, rech2, rech3, rech4, "object"); } else { System.out.println("Process type"); gArray[i] = graph.insertVertex(defaultParent, null, sArray[i], rech1, rech2, rech3e, rech4, "process"); } rech1 += 100; rech2 += 100; } for (int i = 2; i <= rowct; i++) { if (a[i][3].equals("Two Way") || a[i][3].equals("TWO WAY") || a[i][3].equals("TwoWay") || a[i][3].equals("TWOWAY") || a[i][3].equals("2 Way") || a[i][3].equals("Two way")) { System.out.println("Double Edges"); int l1 = 0, l2 = 0; for (int l = 1; l < gArray.length; l++) { System.out.println("gArray.toString=\t" + sArray[l]); System.out.println("gArray.length=\t" + sArray.length); if (sArray[l].equals(a[i][1])) { l1 = l; System.out.println("l2:\t" + l1); } if (sArray[l].equals(a[i][2])) { l2 = l; System.out.println("l2:\t" + l2); } } graph.insertEdge(defaultParent, null, a[i][4], gArray[l1], gArray[l2], "agent"); graph.insertEdge(defaultParent, null, a[i][4], gArray[l2], gArray[l1], "agent"); } else { System.out.println("Single Edges"); int l1 = 0, l2 = 0; for (int l = 1; l < gArray.length; l++) { System.out.println("gArray.toString=\t" + sArray[l]); System.out.println("gArray.length=\t" + sArray.length); if (sArray[l].equals(a[i][1])) { l1 = l; System.out.println("l2:\t" + l2); } if (sArray[l].equals(a[i][2])) { l2 = l; System.out.println("l2:\t" + l2); } } graph.insertEdge(defaultParent, null, a[i][4], gArray[l1], gArray[l2], "agent"); } } graph.setEnabled(true); graph.setAutoSizeCells(true); graph.getModel().endUpdate(); graphComponent = new mxGraphComponent(graph); mxFastOrganicLayout layout = new mxFastOrganicLayout(graph); // define layout //set all properties layout.setMinDistanceLimit(1); //layout.setInitialTemp(5); //layout.setInitialTemp(10); //layout.setForceConstant(10); //layout.setDisableEdgeStyle(true); //layout graph //layout.execute(graph.getDefaultParent()); // layout using morphing String fileWPath; graph.getModel().beginUpdate(); try { layout.execute(graph.getDefaultParent()); } finally { mxMorphing morph = new mxMorphing(graphComponent, 20, 1.2, 20); morph.addListener(mxEvent.DONE, new mxIEventListener() { @Override public void invoke(Object arg0, mxEventObject arg1) { graph.getModel().endUpdate(); // fitViewport(); } }); BufferedImage image; image = mxCellRenderer.createBufferedImage(graph, null, 2, Color.WHITE, true, null); Document d = mxCellRenderer.createVmlDocument(graph, null, 1, Color.WHITE, null); pathToWeb = getServletContext().getRealPath(File.separator); System.out.println("pathtoweb:\t" + pathToWeb); fileWPath = pathToWeb + "genImg\\" + userid + docid + ".png"; System.out.println("filewpath:\t" + fileWPath); //System.out.println(pathToWeb + userid + docid + ".svg"); ImageIO.write(image, "PNG", new File(fileWPath)); XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream( new FileOutputStream(new File(pathToWeb + "genXML\\" + userid + docid + ".xml")))); encoder.writeObject(graph); encoder.close(); morph.startAnimation(); } graphComponent.setConnectable(false); fr.getRootPane().setBorder(BorderFactory.createMatteBorder(4, 4, 4, 4, Color.WHITE)); // Inhibit edge creation in the graph. fr.getContentPane().add(graphComponent); //fr.setVisible(true); request.setAttribute("docidM", docid); request.setAttribute("useridM", userid); request.setAttribute("colCountM", colct); request.setAttribute("rowCountM", rowct); request.setAttribute("fileLinkM", fileWPath); request.setAttribute("pathToWebM", pathToWeb); System.out.println("Iteration Complete"); getServletContext().getRequestDispatcher("/success.jsp").forward(request, response); }