Results 1 to 2 of 2
  1. #1
    santa's Avatar
    santa is offline Senior Member
    Join Date
    Nov 2009
    Location
    Sweden
    Posts
    208
    Rep Power
    6

    Default PLEASE SOMEONE HELP ME =( database.. im desperate

    hi I'v got a brain freeze and what i need to do is :
    Java Code:
    public static void connectDatabase(){
    
     Connection con = null;
     if(database.equals("")){
         JOptionPane.showMessageDialog(null, "Can't run without database!");
         System.exit(0);}
    
        try {
          Class.forName("com.mysql.jdbc.Driver").newInstance();
          con = DriverManager.getConnection("jdbc:mysql://",  // Using anonymous cause i feel like it =)
            "root", "test");
    
    
          if(!con.isClosed())
            System.out.println("Duude youre connected " +
              "trough TCP/IP...");
    
          stmt = con.createStatement();
          try{
          stmt.executeUpdate("USE " + database);
          System.out.println("Used old database!");
          old = true;
            }catch (Exception e){
               stmt.executeUpdate("CREATE DATABASE " + database);
               stmt.executeUpdate("USE " + database);
               System.out.println("Database created!");
            }
          if(!old){
          stmt.executeUpdate ("CREATE TABLE Borrowers ("
                  + "cardnr INT,"
                  + "name CHAR(60), "
                  + "street CHAR(40), "
                  + "zip INT,"
                  + "town CHAR(50),"
                  + "id INT NOT NULL AUTO_INCREMENT PRIMARY KEY)");
    
                  stmt.executeUpdate ("CREATE TABLE GoodBooks ("
             + " ISBN long,"
            + " CopyNumber INT,"
            + " Title VARCHAR(60),"
            + " Author VARCHAR(30),"
            + " Publisher VARCHAR(50),"
            + " Year INT,"
            + " Statistics INT,"
            + " BorrowDate INT,"
            + " ReturnDate INT,"
            + " LibraryCardNumber INT,"
                          + "id INT NOT NULL AUTO_INCREMENT PRIMARY KEY)");
            }
          if(!old){
       for(int j = 0 ; j < Borrowers.borrow.length; j++){
                     stmt.executeUpdate("INSERT INTO Borrowers "
                             +"(cardnr, name, street, zip, town) "
                             + "VALUES "
                             + "('"+ Borrowers.borrow[j].LibraryCardNumber + "',"
                             + "'"+ Borrowers.borrow[j].Name + "',"
                             + "'"+ Borrowers.borrow[j].Street + "',"
                             + "'"+ Borrowers.borrow[j].ZipCode + "',"
                             + "'"+ Borrowers.borrow[j].Town + "')");
            }
    
    
    
    
    
    
    
    for(int j = 0 ; j <Bookobjects.bookO.length ; j++){
                     stmt.executeUpdate("INSERT INTO goodbooks "
                             +"(ISBN, CopyNumber, Title, Author, Publisher, Year, Statistics,"
                             + " BorrowDate, ReturnDate, LibraryCardNumber) "
                             + "VALUES "
                             + "('"+ Bookobjects.bookO[j].ISBN + "',"
                             + "'"+ Bookobjects.bookO[j].CopyNumber + "',"
                             + "'"+ Bookobjects.bookO[j].Title + "',"
                             + "'"+ Bookobjects.bookO[j].Author + "',"
                             + "'"+ Bookobjects.bookO[j].Publisher + "',"
                             + "'"+ Bookobjects.bookO[j].Year + "',"
                             + "'"+ Bookobjects.bookO[j].Statistics + "',"
                             + "'"+ Bookobjects.bookO[j].BorrowDate + "',"
                             + "'"+ Bookobjects.bookO[j].ReturnDate + "',"
                             + "'"+ Bookobjects.bookO[j].LibraryCardNumber + "')");
            }
      
    
    
            }
    
        }catch(Exception e) {
          System.err.println("Fail: " + e.getMessage());
          System.out.println("Fail: " + e);
        }
    if old is true ... update database
    check in for Bookobjects.bookO.length and
    Borrowers.borrow.length for new objects

    Thank you for any help =P

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,225
    Rep Power
    20

    Default

    So, what happens when you run that?
    What's your problem?

    Errors?
    Exceptions?

Similar Threads

  1. help i'm desperate
    By AniMaind in forum New To Java
    Replies: 17
    Last Post: 01-08-2011, 02:05 AM
  2. Desperate for some help if possible :(
    By SBOSlayer in forum New To Java
    Replies: 1
    Last Post: 11-30-2010, 11:44 PM
  3. Replies: 2
    Last Post: 02-11-2009, 05:43 AM
  4. In Desperate need for a good swing website
    By Loop in forum New To Java
    Replies: 4
    Last Post: 09-30-2008, 03:23 PM
  5. Multithreading + Networking (desperate)
    By bluebarca in forum New To Java
    Replies: 1
    Last Post: 11-07-2007, 03:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •