Hello,
I have to connect Robocode in a Database. It's like when when I press 'W' on the keyboard it will write a ahead in the database.
I know how to do that, but I dont know how to start the database with robocode. Because Robocode only start the run() method. Its an HSQLDB with JBDC.
publicclassTastaturbotextendsAdvancedRobot{privateConnectionconnection;/** * Connect to a storage database and store the connection. * @throws SQLException */publicTastaturbot()throwsSQLException{this("jdc:hsqldb:hsql://localhost/dbbot", "usr", "ooz1ooHi"); } /** * Connect to a database and store the connection. * @param url A JDBC URL. * @param username A user name for the database connection. * @param password The corresponding password to the user name. * @throws SQLException */ public Tastaturbot(String url, String username, String password) throws SQLException { // Probe HSQLDB driver try { Class.forName("org.hsqldb.jdbc.JDBCDriver"); } catch (Exception e) { System.err.println("Couldn'tfindHSQLDBJDBCdriver.Haveyoureferencedthelibrary?");System.exit(1);}this.connection=DriverManager.getConnection(url,username,password);}intmoveDirection;//Forward-Backward1=MoveForward0=Standstill-1=MoveBackwardintturnDirection;//Left-Right1=TurnRight0=NoTurning-1=TurnLeftdoublemoveAmount;intfirePower;publicvoidrun(){//HEREIWANTTOCALLTHEDATABASETOSTART,BUTONLYRUN()START.while(true){setAhead(moveAmount*moveDirection);//moveamount=postivunendlichsetTurnRight(45*turnDirection);//degrees-1*45oder1*45if(firePower>0){setFire(firePower);//Firewirdbeliebigoftausgelöst}execute();}}
Last edit: Franak 2017-06-23
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
First of all. The robots in Robocode is not intended to write to external
files, databases etc. due to security reasons (robots will be able to write
data to other peoples disks etc.).
Writing to a database is out of scope for normal use of Robocode.
I don't know what you are trying to achieve by writing to the database. But
normally I would let the RobocodeEngine handle stuff like that - not the
individual robots.
But it is possible to write to a database, if you disable the internal
Robocode Security Manager by adding -DNOSECURITY=true to the robocode.bat
file (make a copy first).
Before putting database stuff in a Robocode robot, you should make some
code that works out-of-the-box beside Robocode. When you get this code up
and running, and it works as expected, then you can move it to Robocode.
Hello,
I have to connect Robocode in a Database. It's like when when I press 'W'
on the keyboard it will right a ahead in the database.
I know how to do that, but I dont know how to start the database with
robocode. Because Robocode only start the run() method. Its an HSQLDB with
JBDC.
public class Tastaturbot extends AdvancedRobot{
privateConnectionconnection;/** * Connect to a storage database and store the connection. * @throws SQLException */publicTastaturbot()throwsSQLException{this("jdc:hsqldb:hsql://localhost/dbbot", "usr", "ooz1ooHi");}/** * Connect to a database and store the connection. * @param url A JDBC URL. * @param username A user name for the database connection. * @param password The corresponding password to the user name. * @throws SQLException */public Tastaturbot(String url, String username, String password) throws SQLException { // Probe HSQLDB driver try { Class.forName("org.hsqldb.jdbc.JDBCDriver"); } catch (Exception e) { System.err.println("Couldn'tfindHSQLDBJDBCdriver.Haveyoureferencedthelibrary?");System.exit(1);}this.connection=DriverManager.getConnection(url,username,password);}intmoveDirection;//Forward-Backward1=MoveForward0=Standstill-1=MoveBackwardintturnDirection;//Left-Right1=TurnRight0=NoTurning-1=TurnLeftdoublemoveAmount;intfirePower;publicvoidrun(){//HEREIWANTTOCALLTHEDATABASETOSTART,BUTONLYRUN()START.while(true){setAhead(moveAmount*moveDirection);//moveamount=postivunendlichsetTurnRight(45*turnDirection);//degrees-1*45oder1*45if(firePower>0){setFire(firePower);//Firewirdbeliebigoftausgelöst}execute();}}
Hello,
I have to connect Robocode in a Database. It's like when when I press 'W' on the keyboard it will write a ahead in the database.
I know how to do that, but I dont know how to start the database with robocode. Because Robocode only start the run() method. Its an HSQLDB with JBDC.
Last edit: Franak 2017-06-23
Hi Franak,
First of all. The robots in Robocode is not intended to write to external
files, databases etc. due to security reasons (robots will be able to write
data to other peoples disks etc.).
Writing to a database is out of scope for normal use of Robocode.
I don't know what you are trying to achieve by writing to the database. But
normally I would let the RobocodeEngine handle stuff like that - not the
individual robots.
But it is possible to write to a database, if you disable the internal
Robocode Security Manager by adding -DNOSECURITY=true to the robocode.bat
file (make a copy first).
Before putting database stuff in a Robocode robot, you should make some
code that works out-of-the-box beside Robocode. When you get this code up
and running, and it works as expected, then you can move it to Robocode.
Best regards,
- Flemming
fre. 23. jun. 2017 kl. 09.39 skrev Franak franktheacer@users.sf.net: