Username:   Password:  

test

/***********************************************************************************************************************
* Description      : PLUSGMOC class
*
*					 * This class generates the TB autonumbering and revisioning for Technical
*					 Bulletin application.
*
* Created For      :
* Modification Log :
* -----------------------------------------------------------------------------------------------
* Date                 Author                       Description
* -----------------------------------------------------------------------------------------------
* 20/04/2010           Infosys       				Initial Version
**************************************************************************************************************************/
 
//WORKORDER Package
package com.custom.app.workorder;
 
//JAVA Imports
import java.rmi.RemoteException;
import psdi.mbo.MboSet;
import psdi.security.UserInfo;
import psdi.util.BidiUtils;
import psdi.util.MXException;
import psdi.util.MXApplicationException;
import java.util.Calendar;
import java.util.Date;
import psdi.mbo.MboRemote;
import psdi.mbo.MboSetRemote;
import psdi.mbo.MboConstants;
import com.custom.app.workorder.PlusGMOCRequest;
import java.text.DateFormat;
//Extending OOB PlusGMOC
public class PlusGMOC extends psdi.plusg.app.workorder.PlusGMOC
implements  com.custom.app.workorder.PlusGMOCRemote
{
	//Constructor
	public PlusGMOC(MboSet mboset)
	throws MXException, RemoteException
	{
		//Calling super
		super(mboset);
	}
 
  	public void init() throws MXException
  	{
 
		System.out.println("PlusGMOC :: init() :: Inside init method");
		super.init();
		try
		{
			  System.out.println("PlusGMOC :: init() :: Application Name "+getThisMboSet().getApp());
			  System.out.println("PlusGMOC :: init() :: WONUM "+getString("WONUM"));
		}
		catch (RemoteException e)
		{
			  // TODO Auto-generated catch block
			  e.printStackTrace();
		}
  	}
 
 
	/*-----------------------------------------------------------------------------------------------------------------------------------
	 * Description       :  Overridden the add method of the PLUSGMOC Mbo.
	 * Parameters        :  NA
	 * Return Value      :  void
	 * Modification Log  :
	 * ----------------------------------------------------------------------------------------------------------------------------------
	 * Date          Author            Description
	 * ----------------------------------------------------------------------------------------------------------------------------------
	 * 25/03/2010	 Infosys  	Generating the autonumbering and setting the WONUM and BHITBNUMBER
	 *							attribute accordingly.(Have suppressed it from configuration to avoid wastage.)
	 *
	 * 25/03/2010	 Infosys    TB numbering revision logic to generate subsequent TBs to have revision #(B,C, and so on)
	 *							where I, O, Q, S, V, X,Z should never be used for revisions and Upon exhaustion of the alphabet,
	 *							revisions should be identified by AA, AB, AC, etc, then BA, BB, etc.and so on.
	 *
	 * -----------------------------------------------------------------------------------------------------------------------------------
	 */
	public void add() throws MXException,RemoteException
	{
		//Calling super
		super.add();
		System.out.println("PlusGMOC :: add() :: Application Name : "+getThisMboSet().getApp());
		String str_appName = getThisMboSet().getApp();
		String strWoClass = getString("WOCLASS");
		System.out.println("PlusGMOC :: add() :: WOCLASS : "+strWoClass);
 
		if ("PLUSGMOC".equals(str_appName) || str_appName==null)
		{
			System.out.println("PlusGMOC :: add() :: It's Not a TB application.");
			this.generateAutoKey();
			System.out.println("PlusGMOC :: add() :: WONUM = "+getString("WONUM"));
		}
		else if (str_appName.equals("BHITB"))
		{
			if (((PlusGMOCSet) getThisMboSet()).getIsRevisedTB())
			{
				String str_revisedTB=null;
				String strPreWoNum = ((PlusGMOCSet) getThisMboSet()).getPreWoNum();
				if(strPreWoNum.length()!=0)
				{
					int Length = strPreWoNum.length();
					System.out.println("PlusGMOC :: add() ::  Is Revise TB :: Length is " +Length);
					char character = strPreWoNum.charAt(Length-1);
					System.out.println("PlusGMOC :: add() ::  Is Revise TB :: Last char is " +character);
 
					//Check if the last character is a numeric value.If a numeric value then
					//  append the revision number with -A.
					if (character == '0' || character == '1' || character == '2' || character == '3' || character == '4' || character == '5' || character == '6' || character == '7' || character == '8' || character == '9')
					{
						int i = 65;
						str_revisedTB = strPreWoNum+"-"+(char)i;
					}
					else
					{
						// If the last character is not a numeric value then depending on the number
						//  of characters after last -,calculate the revision number.
						int LastIndex = strPreWoNum.lastIndexOf("-");
						System.out.println("PlusGMOC :: add() ::  Is Revise TB :: LastIndex is " +LastIndex);
						System.out.println("PlusGMOC :: add() ::  Is Revise TB :: Last alphabets after - is "+strPreWoNum.substring(LastIndex, Length));
 
						// If the last character in the revision number is -Y then the new number is -AA.
						// e.g.if WONUM = TB-1000-Y then the next revision number is TB-1000-AA.
						if(strPreWoNum.substring(LastIndex, Length-1).length() == 1 && strPreWoNum.substring(LastIndex, Length).equalsIgnoreCase("-Y") )
						{
							System.out.println("PlusGMOC :: add() ::  Is Revise TB :: Last alphabet is " +strPreWoNum.substring(LastIndex+1, Length));
							character = (char)65;
							System.out.println("PlusGMOC :: add() ::  Is Revise TB :: New WONUM is " +(strPreWoNum.substring(0, Length-1)+character+character));
							str_revisedTB = strPreWoNum.substring(0, Length-1)+character+character;
						}
						// If the last character in the revision number is not -Y then the new number is the next increment.
						// e.g.if WONUM = TB-1000-B then the new revision number is TB-1000-C.
						if(strPreWoNum.substring(LastIndex, Length-1).length() == 1 && !strPreWoNum.substring(LastIndex, Length).equalsIgnoreCase("-Y") )
						{
							System.out.println("PlusGMOC :: add() ::  Is Revise TB :: Last alphabet is " +strPreWoNum.substring(LastIndex+1, Length));
							int i = (int)character;
							System.out.println("PlusGMOC :: add() ::  Is Revise TB :: Last alphabet's ASCII is " +i);
							i = i+1;
 
							// The revision number should not contain following alphabets:
							// I, O, Q, S, V, X, Z
							// If the revision number contains H then the new number should skip I.
							// e.g.if WONUM = TB-1000-H then the new revision number is TB-1000-J.
							if((i != 73) && (i != 79) && (i != 81) && (i != 83) && (i != 86) && (i != 88) && (i != 90))
							{
								character = (char)i;
								System.out.println("PlusGMOC :: add() ::  Is Revise TB :: New WONUM is " +(strPreWoNum.substring(0, Length-1)+character));
								str_revisedTB = strPreWoNum.substring(0, Length-1)+character;
							}
							else
							{
								character = (char)(i+1);
								System.out.println("PlusGMOC :: add() ::  Is Revise TB :: Else New WONUM is " +(strPreWoNum.substring(0, Length-1)+character));
								str_revisedTB = strPreWoNum.substring(0, Length-1)+character;
							}
						}
 
						// If the last character in the revision number is not -YY then the new number is the next increment.
						// e.g.if WONUM = TB-1000-AB then the new revision number is TB-1000-AC.
						if(strPreWoNum.substring(LastIndex, Length-1).length() == 2 && !strPreWoNum.substring(LastIndex, Length).equalsIgnoreCase("-YY"))
						{
							if(!strPreWoNum.substring(LastIndex+2, Length).equalsIgnoreCase("Y"))
							{
								int i = (int)character;
								i = i+1;
 
								// The revision number should not contain following alphabets:
								// I, O, Q, S, V, X, Z
								// If the revision number contains H then the new number should skip I.
								// e.g.if WONUM = TB-1000-H then the new revision number is TB-1000-J.
								if((i != 73) && (i != 79) && (i != 81) && (i != 83) && (i != 86) && (i != 88) && (i != 90))
								{
									character = (char)i;
									System.out.println("PlusGMOC :: add() ::  Is Revise TB :: character is " +character);
									System.out.println("PlusGMOC :: add() ::  Is Revise TB :: New WONUM is " +(strPreWoNum.substring(0, Length-1)+character));
									str_revisedTB = strPreWoNum.substring(0, Length-1)+character;
								}
								else
								{
									character = (char)(i+1);
									System.out.println("PlusGMOC :: add() ::  Is Revise TB :: New WONUM is " +(strPreWoNum.substring(0, Length-1)+character));
									str_revisedTB = strPreWoNum.substring(0, Length-1)+character;
								}
							}
							else
							{
								// If the revision number contains Y in the end then the new number increments.
								// e.g.if WONUM = TB-1000-AY then the new revision number is TB-1000-BA.
								character = strPreWoNum.charAt(Length-2);
								System.out.println("PlusGMOC :: add() ::  Is Revise TB :: First char is "+character);
								int i = (int)character;
								i = i+1;
 
								// The revision number should not contain following alphabets:
								// I, O, Q, S, V, X, Z
								// If the revision number contains H then the new number should skip I.
								// e.g.if WONUM = TB-1000-H then the new revision number is TB-1000-J.
								if((i != 73) && (i != 79) && (i != 81) && (i != 83) && (i != 86) && (i != 88) && (i != 90))
								{
									character = (char)i;
									System.out.println("PlusGMOC :: add() ::  Is Revise TB :: New WONUM is " +strPreWoNum.substring(0, Length-2)+character+(char)65);
									str_revisedTB = strPreWoNum.substring(0, Length-2)+character+(char)65;
								}
								else
								{
									character = (char)(i+1);
									System.out.println("PlusGMOC :: add() ::  Is Revise TB :: New WONUM is " +strPreWoNum.substring(0, Length-2)+character+(char)65);
									str_revisedTB = strPreWoNum.substring(0, Length-2)+character+(char)65;
								}
							}
						}
						if(strPreWoNum.endsWith("-YY"))
						{
							System.out.println("PlusGMOC :: add() ::  Is Revise TB :: Cannot create ReviseTB after "+strPreWoNum);
							throw new MXApplicationException("TB","BHIReviseTB");
						}
					}
				}
				//Set the revised TB Number generated on BHITBNUMBER and WONUM
				System.out.println("PlusGMOC :: add() ::  Is Revise TB :: str_revisedTB =="+str_revisedTB);
				this.setValue("BHITBNUMBER",str_revisedTB);
				setValue("WONUM",getString("BHITBNUMBER"));
				String strReportedBy1 = getString("REPORTEDBY");
				System.out.println("PlusGMOC :: add() :: strReportedBy1 = "+strReportedBy1);
				setValue("OWNER",strReportedBy1);
				setValue("WOCLASS","TB");
				System.out.println("PlusGMOC :: add() ::  Is Revise TB :: WONUM= "+getString("WONUM"));
				getThisMboSet().setApp("BHITB");
				System.out.println("PlusGMOC :: add() ::  Application Name ="+getThisMboSet().getApp());
				this.changeStatus("DRAFT",null,"Draft", 11L);
				System.out.println("PlusGMOC :: add() :: STATUS = "+getString("STATUS"));
			}
			else
			{
				this.getMboValue("BHITBNUMBER").autoKey();
				String str_woNum= getString("BHITBNUMBER")+"-A";
				setValue("BHITBNUMBER",str_woNum);
				setValue("WONUM",getString("BHITBNUMBER"));
				String strReportedBy = getString("REPORTEDBY");
				System.out.println("PlusGMOC :: add() :: strReportedBy = "+strReportedBy);
				setValue("OWNER",strReportedBy);
				setValue("WOCLASS","TB");
 
				System.out.println("PlusGMOC :: add() :: WONUM = "+getString("WONUM"));
				System.out.println("PlusGMOC :: add() :: BEFORE STATUS = "+getString("STATUS"));
				this.changeStatus("DRAFT",null,"Draft", 11L);
				System.out.println("PlusGMOC :: add() :: STATUS = "+getString("STATUS"));
			}
		}
 	}
	/*------------------------------------------------------------------------------------------------------------
	 * Description       :  Created new method createTB in PLUSGMOC Mbo.
	 * Parameters        :  String
	 * Return Value      :  MboRemote
	 * Modification Log  :
	 * -----------------------------------------------------------------------------------------------------------
	 * Date          Author            Description
	 * -----------------------------------------------------------------------------------------------------------
	 * 10/05/2010	 Infosys/Jai      This method is invoked while creating a revise TB
	 * -----------------------------------------------------------------------------------------------------------
	 */
	public MboRemote createTB(String s)
	throws MXException, RemoteException
	{
		System.out.println("PlusGMOC :: createTB()");
		MboSet mboset = (MboSet)(MboSet)getMboServer().getMboSet(s, getUserInfo());
		System.out.println("PlusGMOC :: createTB() :: mboset = "+mboset);
 
		mboset.setInsertSite(getString("siteid"));
		mboset.setInsertOrg(getString("orgid"));
 
		//Set the Application name
		mboset.setApp("BHITB");
		System.out.println("PlusGMOCRequest :: createTB() :: app name = "+getThisMboSet().getApp());
		System.out.println("PlusGMOC :: createTB() :: current wonum = "+getString("WONUM"));
 
		//If the Application is TB, then set the previous WONUM and isRevisedTB to true on current MBOSet
		if ("BHITB".equals(getThisMboSet().getApp()))
		{
			((PlusGMOCSet) mboset).setPreWoNum(getString("WONUM"));
			((PlusGMOCSet) mboset).setIsRevisedTB(true);
		}
		((PlusGMOCSet) mboset).setWoClass("TB");
		MboRemote mboremote = mboset.add();
		System.out.println("PlusGMOC :: Revised TB # = "+mboremote.getString("WONUM"));
		System.out.println("PlusGMOC :: createTB() :: 1");
		UserInfo userinfo = mboremote.getUserInfo();
		userinfo.setInteractive(false);
		mboremote.setValue("origrecordid", getString("wonum"), 11L);
		System.out.println("PlusGMOC :: createTB() :: origrecordid = "+mboremote.getString("ORIGRECORDID"));
		mboremote.setValue("origrecordclass", getString("woclass"), 11L);
		mboremote.setValue("origwoid", getString("wonum"), 2L);
		if(!mboremote.isNull("origrecordid"))
		{
			mboremote.setValue("reportedby", userinfo.getPersonId(), 2L);
		}
		System.out.println("PlusGMOC :: createTB() :: 2");
		doClassificationCreateWOViews(mboremote);
		System.out.println("PlusGMOC :: createTB() :: 3");
		setValue("hasfollowupwork", true, 2L);
		mboremote.setValueNull("onbehalfof");
		mboremote.setValue("plusgpmnumref", getString("plusgpmnumref"), 11L);
		mboremote.setValue("jpnum", getString("jpnum"), 11L);
		if(!mboremote.getString("assetnum").equalsIgnoreCase("") && !mboremote.getString("location").equalsIgnoreCase(""))
		{
			if(!getString("assetnum").equalsIgnoreCase(mboremote.getString("assetnum")))
			{
				mboremote.setValue("assetnum", getString("assetnum"), 2L);
			}
			if(!getString("location").equalsIgnoreCase(mboremote.getString("location")))
			{
				mboremote.setValue("location", getString("location"), 2L);
			}
		}
		userinfo.setInteractive(true);
		System.out.println("PlusGMOC :: createTB() :: Creating related record.");
		MboSetRemote mbosetremote = mboremote.getMboSet("RELATEDRECORD");
		MboRemote mboremote1 = mbosetremote.add();
		mboremote1.setValue("relatedreckey", getString("wonum"), 11L);
		System.out.println("PlusGMOC :: createTB() :: related record key = "+mboremote1.getString("RELATEDRECKEY"));
		mboremote1.setValue("relatedrecclass", getString("woclass"), 11L);
		mboremote1.setValue("relatedrecsiteid", getString("siteid"), 11L);
		mboremote1.setValue("relatedrecorgid", getString("orgid"), 11L);
		mboremote1.setValue("relatetype", getTranslator().toExternalDefaultValue
			
			

sakesh_snippet

import java.io.*;
import ariba.util.scheduler.ScheduledTask;
import ariba.util.scheduler.ScheduledTaskException;
import ariba.base.core.Base;
import ariba.base.core.BaseId;
import ariba.base.core.aql.*;
import ariba.base.core.Partition;
import ariba.base.fields.ValueSource;
import ariba.collaborate.util.CollaborateUtil;
import ariba.collaborate.util.Log;
import java.sql.*;
import ariba.util.core.IOUtil;
import java.io.IOException;
import ariba.util.core.SystemUtil;
import java.util.Map;
import ariba.base.core.Partition;
import java.util.Iterator;
 
// queryString  - Will be the above query
// exportFile – Will be the location of file
 
 public void extractDoc(String queryString,String exportFile) throws Exception 
 
{
 
        try
 {
           // Creating database connection 
 
 	String driverName = "oracle.jdbc.driver.OracleDriver";
            Class.forName(driverName);
            Connection conn = DriverManager.getConnection(url, username, password);
            Statement stmt = conn.createStatement();
 
            // Executing the query
 
ResultSet results = stmt.executeQuery(queryString);
           debug(" results size :"+results.getFetchSize());
 
 
// result set contains details of all the documents linked to a 
particular project            
while(results.next())
            {
 
           // project internal id  
           String wsInternalId = results.getString(6);
 
          // Status of document		
            String Status = results.getString(7);
 
// If we are extracting the documents for multiple projects we need to create          separate folders in the file system for each project.
 
String FolderName = results.getString(6); // we are giving InternalId of project as folder name
 
	// Getting blob object.
             Blob blob = results.getBlob(2);
 
           // Title of the document, title also contains the extension of the file.
              So we  don’t need to worry about the extension of the file.
 
            String documentTitle = (String)results.getString(3);
 
            String folderName = exportFile+"/"+FolderName; 
 
// so if exportFile value is like config/../data/Extract_Document then
folder structure could be like thisconfig/../data/ExtractDocument/InternalID(value)
 
 
           // getting binary stream from blob object
            InputStream blobStream = blob.getBinaryStream();
 
            File file = new File(folderName);
            file.mkdirs();
 
            String fileName = folderName +"/" + documentTitle;
          // fileName would be like 
             config/../data/ExtractDocument/InternalId(value)/XXX.FileExtension
 
            File fileOut = new File(fileName);
 
           debug("Calling writeToFile function to write the csv in Document");
           writeToFile(blobStream, fileOut);
}
 
 
private void writeToFile (InputStream in, File outputFile) throws Exception 
{
        FileOutputStream out = new FileOutputStream(outputFile);
 
        // We are using ariba IOUtil instead of java functionality 
        boolean written = IOUtil.inputStreamToOutputStream(in, out);
 
 if(written) 
       	{
            	debug("Done !!!");
        	}
 else
       	{
            	debug("Error while writing file...");
            	throw new Exception("Error in writing output file");
        	}
 }
 

test

	import java.io.FileOutputStream;
	import java.io.IOException;
	import java.io.InputStream;
	import java.io.OutputStream;
 
	public class Test
	{
		public static void main (String args[]) throws IOException
		{
			String from = "D:/src/test.jpg";
			String to = "D:/dest/test.jpg";
			copy(from, to);
		}
		public static void copy (String from, String to) throws IOException
		{
			InputStream in = null;
			OutputStream out = null;
			System.out.println(System.currentTimeMillis())
			{
				try
				{
					InputStream inFile = new FileInputStream (from);
					in = new BufferedInputStream (inFile);
					OutputStream out = new FileOutputStream (to);
					out = new BufferedOutputstream (outFile);
					while (true)
					{
						int data = in.read();
						if (data == -1)
						{
							break;
						}
						out.write(data);
					}
					System.out.println(System.currentTimeMillis());
				}
				finally
				{
					if (in != null)
					{
						in.close();
					}
					if (out != null)
					{
						out.close();
					}
				}
			}
		}

test

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
 
public class Test
{
	public static void main (String args[]) throws IOException
	{
		String from = "D:/src/test.jpg";
		String to = "D:/dest/test.jpg";
		copy(from, to);
	}
	public static void copy (String from, String to) throws IOException
	{
		InputStream in = null;
		OutputStream out = null;
		System.out.println(System.currentTimeMillis())
		{
			try
			{
				in = new FileInputStream(from);
				out = new FileOutputStream(to);
				while(true)
				{
					int data = in.read();
					if (data == -1)
					{
						break;
					}
					out.write(data)
				}
				System.out.println(System.currentTimeMillis())
			}
			finally
			{
				if (in != null)
				{
					in.close();
				}
				if (out != null)
				{
					out.close();
				}
			}
		}
	}

test

int iSize = strTest.size();
for (int iIndex = 0; iIndex < iSize; iIndex++)

test

int iSize = strTest.size();
for (int iIndex = 0; iIndex < iSize; iIndex++

tset

for (int iIndex = 0; iIndex < strTest.size(); iIndex++)

test

public class TestVarAccess1
{
	private int instanceVariable;
	private static int staticVariable;
 
	void localVarAccess(int val)
	{
		int localVariable = 0;
		for (int i = 0; i < val; i++)
		{
			localVariable += i;
		}
	}
	void staticVarAccess(int val)
	{
		int localVar = staticVariable;
		for (int i = 0; i < val; i++)
		{
			localVar += i;
		}
		staticVariable = localVar;
	}
	void instanceVarAccess(int val)
	{
		int localVarbl = instaceVariable;
		for (int i = 0; i < val; i++)
		{
			localVarbl += i;
		}
		instanceVariable = localVarbl;
	}
}

test

package config.java;
public class TestVarAccess
{
	private int instanceVariable;
	private static int staticVariable;
 
	void localVarAccess(int val)
	{
		int localVariable = 0;
		for (int i = 0; i < val; i++)
		{
			localVariable += i;
		}
	}
	void staticVarAccess(int val)
	{
		for (int i = 0; i < val; i++)
		{
			staticVariable += i;
		}
	}
	void instanceVarAccess(int val)
	{
		for (int i = 0; i < val; i++)
		{
			instanceVariable += i;
		}
	}
}

test

package config.java;
 
public class TestVarAccess
{
	private int instanceVariable;
	private static int staticVariable;
 
	void localVarAccess(int val)
	{
		int localVariable = 0;
		for (int i = 0; i < val; i++)
		{
			localVariable += i;
		}
	}
	void staticVarAccess(int val)
	{
		for (int i = 0; i < val; i++)
		{
			staticVariable += i;
		}
	}
	void instanceVarAccess(int val)
	{
		for (int i = 0; i < val; i++)
		{
			instanceVariable += i;
		}
	}
}

tset

package config.java;
 
import java.io.FileInputStream;
import java.io.FileNotFoundException;
 
public class Test
{
	String strFileName = "D:/test/test.jpg";
	public static FileInputStream fi (String strFileName)
		throws FileNotFoundException
		{
			FileInputStream fis = new FileInputStream (strFileName)
			System.out.println("fi:FileInputStream created");
			return fis;
		}
}

tesyt

public static boolean Mytest2(Requisituin req)
{
	if (req instanceof Requisition)
	{
		return false;
	}
	else
	{
		return true;
	}
}

test

public static exception EXCEPTIONREUSE = new Exception();
 
//Much Faster
 
try
{
	throw EXCEPTIONREUSE;
}
catch (Exception e)
{
	...
}
 
//Much Slower
 
try
{
	throw new Exception;
}
catch (Exception e)
{
	....
}

test

package config.java;
 
public class Test
{
	public String ReqLineNumber()
	{
		return new StringBuffer.append("This").append("is").append("a class").
		append(Requisition.ClassName).toString();
	}
}

test

package config.java;
 
public class Test
{
	public String ReqLineNumber()
	{
		return "This" + "is" + "a test" + Requisition.ClassName;
	}
}

test

package config.java;
 
public class Test
{
	public String ReqLineNumber()
	{
		return "This" + "is" + "a test";
	}
}

test

package config.java;
import java.io.IOException;
import ariba.util.log.Log;
public class Requisition
{
	public static final String ClassName = "Requisition";
	public static void main(String args[]) throws IOException
	{
		Requisition[] requisition = new Requisition[100];
		for (int iIndex = 0; iIndex < 100; iIndex++)
		{
			requisition[iIndex] = new Requisition();
			Log.customer.debug("%s :: This is a test class",ClassName);
		}
	}
}

test

package config.java;
import java.io.IOException;
public class Test
{
	public static void main(String args[]) throws IOException
	{
		StringBuffer buffer = new StringBuffer();
		for (int iIndex = 0; iIndex < 100; iIndex++)
		{
			buffer.append("test");
		}
	}
}

trest

test

package config.java;
import java.io.IOException;
public class Test
{
	public static void main(String args[]) throws IOException
	{
		for (int iIndex = 0; iIndex < 100; iIndex++)
		{
			StringBuffer buffer = new StringBuffer();
			buffer.append("test");
		}
	}
}

test

Tags

test

Example of MySQL connection in Java

#
#   mysql-connector-java-3.0.11-stable-bin.jar or later must be downloaded
#   from:http://dev.mysql.com/downloads/connector/j/3.0.html
#
#   Compile:
#     javac Connect.java
#
#   Run:
#     java Connect
 
import java.sql.*;
 
public class Connect
{
	public static void main (String[ ] args)
	{
	Connection conn = null;
	String url = "jdbc:mysql://localhost/";
	String userName = "root";
	String password = "";
 
	try
	{
		Class.forName ("com.mysql.jdbc.Driver").newInstance ( );
		conn = DriverManager.getConnection (url, userName, password);
		System.out.println ("Connected");
	}
	catch (Exception e)
	{
		System.err.println ("Cannot connect to server");
	}
	finally
	{
		if (conn != null)
		{
			try
			{
				conn.close ( );
				System.out.println ("Disconnected");
			}
			catch (Exception e) { /* ignore close errors */ }
		}
	}
}

Shows how to connecto to a MySQL database with Java.

Tags

Java MySQL