Visualizzazione dei risultati da 1 a 6 su 6
  1. #1
    Utente di HTML.it
    Registrato dal
    Sep 2007
    Messaggi
    115

    Connettere java con il database McKoi

    salve ragazzi ho necessita di connettere un progammino java al database...ho letto parecchie guige e tutti parlano della connessione client---driver---database...

    leggendo un capito di un libro mi da il codice java ma non mi dice come installare il database... il codice e il seguente:

    codice:
    import java.sql.*;
    import java.io.*;
    import java.util.*;
    
    /**
       This program tests that the database and the JDBC 
       driver are correctly configured.
    */
    class TestDB
    {  
       public static void main (String args[])
       {  
          try
          {  
             runTest();
          }
          catch (SQLException ex)
          {  
             while (ex != null)
             {  
                ex.printStackTrace();
                ex = ex.getNextException();
             }
          }
          catch (IOException ex)
          {  
             ex.printStackTrace();
          }
       }
    
       /**
          Runs a test by creating a table, adding a value, showing the table contents, and 
          removing the table.
       */
       public static void runTest()
          throws SQLException, IOException
       {
          Connection conn = getConnection();
          try
          {
             Statement stat = conn.createStatement();
             
             stat.execute("CREATE TABLE Greetings (Message CHAR(20))");
             stat.execute("INSERT INTO Greetings VALUES ('Hello, World!')");
             
             ResultSet result = stat.executeQuery("SELECT * FROM Greetings");
             result.next();
             System.out.println(result.getString(1));
             stat.execute("DROP TABLE Greetings");      
          }
          finally
          {
             conn.close();
          }
       }
    
       /**
          Gets a connection from the properties specified
          in the file database.properties
          @return the database connection
       */
       public static Connection getConnection()
          throws SQLException, IOException
       {  
          Properties props = new Properties();
          FileInputStream in = new FileInputStream("database.properties");
          props.load(in);
          in.close();
    
          String drivers = props.getProperty("jdbc.drivers");
          if (drivers != null)
             System.setProperty("jdbc.drivers", drivers);
          String url = props.getProperty("jdbc.url");
          String username = props.getProperty("jdbc.username");
          String password = props.getProperty("jdbc.password");
    
          return DriverManager.getConnection(url, username, password);
       }
    }
    mi sono scaricato mcKoi ed ho estratto il file mckoidb.jar e lo messo nella cartella dove c'e il file .java! inoltre in questa cartella ho trovato un altro file di nome database.properties!

    mi chiedevo come devo fare per far partire il database...

    help please ^_^
    grazie in anticipo

  2. #2
    Utente di HTML.it L'avatar di andbin
    Registrato dal
    Jan 2006
    residenza
    Italy
    Messaggi
    18,284

    Re: Connettere java con il database McKoi

    Originariamente inviato da cobraa
    ho estratto il file mckoidb.jar e lo messo nella cartella dove c'e il file .java!
    Che stia nella stessa directory dove hai sorgenti non è affatto importante. L'importante è che quel jar sia in "classpath".

    Setting the class path

    Originariamente inviato da cobraa
    mi chiedevo come devo fare per far partire il database...
    http://mckoi.com/database/FAQ.html#7_1
    Andrea, andbin.devSenior Java developerSCJP 5 (91%) • SCWCD 5 (94%)
    java.util.function Interfaces Cheat SheetJava Versions Cheat Sheet

  3. #3
    Utente di HTML.it
    Registrato dal
    Sep 2007
    Messaggi
    115
    ma il jar va estratto??? oppure metto la direcoty direttamente sul file jar??

    come vedi l'inglese non e il mio forte hhiihih

    grazie dell'aiuto ^_^

  4. #4
    Utente di HTML.it
    Registrato dal
    Sep 2007
    Messaggi
    115
    ho seguito la guida online come mi consigliato sono che nel prompt mi esce questo:
    codice:
    Microsoft Windows XP [Versione 5.1.2600]
    (C) Copyright 1985-2001 Microsoft Corp.
    
    C:\Documents and Settings\Cobra>java -jar mckoi.jar
    Unable to access jarfile mckoi.jar
    
    C:\Documents and Settings\Cobra>java -jar mckoidb.jar
    Unable to access jarfile mckoidb.jar
    
    C:\Documents and Settings\Cobra>cd Desktop\mckoi0.94h
    
    C:\Documents and Settings\Cobra\Desktop\mckoi0.94h>java -jar mckoidb.jar
    
    Mckoi SQL Database ( 1.0.3 )
    Copyright (C) 2000 - 2004 Diehl and Associates, Inc.  All rights reserved.
    Use: -h for help.
    
      Mckoi SQL Database comes with ABSOLUTELY NO WARRANTY.
      This is free software, and you are welcome to redistribute it
      under certain conditions.  See LICENSE.txt for details of the
      GPL License.
    
    TCP JDBC Server (multi_threaded) on port: 9157.
    Boot time: 563ms.
    Arrivato qui non mi fa scrivere piu nulla...cosa dovrei fare adesso???

  5. #5
    Utente di HTML.it L'avatar di andbin
    Registrato dal
    Jan 2006
    residenza
    Italy
    Messaggi
    18,284
    Originariamente inviato da cobraa
    ma il jar va estratto???
    No affatto, non devi decomprimerlo!

    Originariamente inviato da cobraa
    ho seguito la guida online come mi consigliato
    Probabilmente non hai letto attentamente. Oltre alla FAQ che ho linkato, c'è anche la documentazione che inizia con il classico "Getting Started".
    Andrea, andbin.devSenior Java developerSCJP 5 (91%) • SCWCD 5 (94%)
    java.util.function Interfaces Cheat SheetJava Versions Cheat Sheet

  6. #6
    Utente di HTML.it
    Registrato dal
    Sep 2007
    Messaggi
    115
    ho cambiato database...sono passato a postgreSQL...solo che ho ancora problemi il codice in java e sempre lo stesso cioe il primo incollato...

    i passi che ho fatto sono questi:
    installato il database; scaricato le JDBC e li ho aggiunti al classpath...ho creato un database con l'interfaccia di pgAdmin III chiando il databse COREJAVA e come indiritto "localhost" ma il software in hava non va....nel programmino in java ho anche trovato un file .properties dove c'e il seguente codice:

    jdbc.drivers=COM.cloudscape.core.JDBCDriver
    jdbc.url=jdbc:cloudscape:COREJAVA;create=true
    jdbc.username=
    jdbc.password=




    questo va modificato???
    mi date una mano per favore...possibile che sono quando chiedo io no trovo risposte esaurienti ma solo link in inglese...che non ci capisco una mazza...
    grazie

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.