Results 1 to 5 of 5
- 08-21-2011, 04:32 PM #1
can someone explain what this exactly does?
so i have writen a small program to create a new player (and also ask them from the database)
Java Code:public Speler registreerSpeler(String naam, SchipKlasse klasse,String schipNaam) { { Speler speler = null; Statement statement; try { Connection connection = PersistentieController.getInstance().getConnection(); statement = connection.createStatement(); String naamCaptain = naam; String ship = schipNaam; String className = klasse.getNaamKlasse(); int hitpoints = klasse.getHitpoints(); int snelheid = klasse.getSpeedpoints(); int cannons = klasse.getCannons(); int rockets = klasse.getRockets(); int AA = klasse.getAA(); int soldiers = klasse.getSoldiers(); int aircrafts = klasse.getAircrafts(); int copters = klasse.getCopters(); int mines = klasse.getMines(); int schadepunten = 0; statement.executeUpdate("INSERT INTO SpelerShip (nameship,classname,hitpoints,speedpoints,cannons,rockets,AA,soldiers,aircrafts,copters,mines,schadepunten) VALUES ('" + ship + "', '" + className + "', '" + hitpoints + "', '" + snelheid + "', '" + cannons + "', '" + rockets + "', '" + AA + "', '" + soldiers + "', '" + aircrafts + "', '" + copters + "','" + mines + "','" + schadepunten + "')"); statement.close(); statement = connection.createStatement(); statement.executeUpdate("INSERT INTO Spelers (naamcaptain,ship) VALUES ('" + naamCaptain + "','" + ship + "')"); //statement.executeUpdate("INSERT INTO Spelers (Naam,Categorie) VALUES ('" + naam + "','" + categorieNaam + "')"); statement.close(); String cmd = "select @@identity from ShipClass"; statement = connection.createStatement(); ResultSet rs = statement.executeQuery(cmd); if (!rs.next()) return null; speler = new Speler(naam, new Schip(klasse, schipNaam, schadepunten)); statement.close(); } catch ( SQLException sqlException ) { sqlException.printStackTrace(); PersistentieController.getInstance().closeConnection(); } return speler; }
this is the code
now i'm only wondering what this does...
this is a picture of the relationship model of my databaseJava Code:String cmd = "select @@identity from ShipClass"; statement = connection.createStatement(); ResultSet rs = statement.executeQuery(cmd); if (!rs.next()) return null;

i know it has to be there in order to work, but i just can't figure out what exactly happens...
tho i will learn this next year i would love to know what it does now.
please help me. :p ^^
grtz liluma
- 08-21-2011, 04:55 PM #2
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,146
- Rep Power
- 5
I don't know what that code is for.
I just wanted to suggest that you use a PreparedStatement for your SQL to make the code more readable and less error prone:
Java Code:String sql = "INSERT INTO Page (Name, Title) VALUES (?, ?)"; PreparedStatement stmt = connection.prepareStatement(sql); stmt.setString( 1, nameVariable ); stmt.setString( 2, titleVariable ); stmt.executeUpdate();
- 08-21-2011, 04:59 PM #3
the program just writes information(strings, int) to a microsoft database...
that function makes a new record in two tables...
i know that preparedStatement are more clear and easier and less likely to make errors...
but i need to be able to do both...
so that's the only reason i used nrml statement here and manually put in the variables... :p
but i know it works correctly i'm just wondering what that last bit of code does...
Java Code:String cmd = "select @@identity from ShipClass"; statement = connection.createStatement(); ResultSet rs = statement.executeQuery(cmd); if (!rs.next()) return null;
- 08-21-2011, 07:55 PM #4
Click here.
db
- 08-21-2011, 07:58 PM #5
Similar Threads
-
Anyone can explain this?
By kazumahits in forum New To JavaReplies: 1Last Post: 03-08-2011, 02:03 AM -
Please Explain me how i got this output.. I am new to java .. so please Explain me...
By vicky82 in forum New To JavaReplies: 2Last Post: 12-13-2010, 01:34 PM -
Please Explain me how i got this output.. I am new to java .. so please Explain me...
By vicky82 in forum New To JavaReplies: 3Last Post: 12-13-2010, 07:22 AM -
Can somebody explain me this plz
By ccie007 in forum New To JavaReplies: 4Last Post: 05-20-2010, 07:47 PM -
Can someone explain why...
By Krooger in forum AWT / SwingReplies: 1Last Post: 11-19-2009, 06:59 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks