High School staff alerted police when they suspected a teenager may have been in possession of drugs.
When officers searched Michal Butlewski they found a lock knife with a four-and-a-half inch blade on it.
The 16-year-old, of Havelock Place, pleaded guilty to being in possession of an offensive weapon at the Common Haugh in Victoria Road on August 16.
Procurator fiscal Morag McLintock told Jedburgh Sheriff Court that staff at the school had raised concerns about the activities of the accused on a Tuesday afternoon around 1.20pm and gave his name to police.
She continued: “Police officers stopped him while he was with a group of other youths on the suspicion he had drugs on him.
“During a search, a knife was found in a jeans pocket.
“He told the officers that a week ago he had been camping and the knife had been in his pocket since then.”
Defence lawyer Rory Bannerman said Butlewski accepted the knife had to be forfeited.
He said: ”He now realises that carrying a knife is a crime in Scotland.
“He will have learned a lesson from this,” added Mr Bannerman.
Sheriff Donald Corke deferred sentence for six months to April 13 for Butlewski to be of good behaviour.