PDA

View Full Version : [JAVA] Non si connette al database


elect
08-11-2009, 19:29
Come da titolo. Quello che devo fare è questo:

First, you have to create an ANT build.xml file. Write two ANT tasks: One for starting the
database server and another one for stopping it. Later in the course, you will use these ANT
tasks to start and stop the database server for the web application.
Your task is to write two SQL-scripts. One in order to create the database structure with its
tables and relations. And another one which fills your newly created tables with test data.
Create an ANT task for each SQL-script, which executes that script.

Questo è il mio build.xml:

<?xml version="1.0" encoding="UTF-8"?>

<project name="FirstLab">
<path id="derby.classpath">
<fileset dir="lib">
<include name="**/*.jar" />
</fileset>
</path>

<target name="server_start">
<java classname="org.apache.derby.drda.NetworkServerControl" classpathref="derby.classpath" fork="true">
<arg value="start" />
</java>
</target>

<target name="server_stop">
<java classname="org.apache.derby.drda.NetworkServerControl" classpathref="derby.classpath" fork="true">
<arg value="shutdown" />
</java>
</target>

<target name="test">
<property name="DBURL" value="jdbc:derby:test" />
<property name="DRIVER" value="lib/org.apache.derby.jdbc.EmbeddedDriver" />
<property name="USERID" value="" />
<property name="PASSWORD" value="" />
<property name="USERS" value="users" />
<property name="IMAGES" value="images" />
<property name="COMMENTS" value="comments" />
<property name="FRIENDSHIP" value="friendship" />
<sql driver="${DRIVER}" url="${DBURL}" userid="${USERID}" password="${PASSWORD}" autocommit="yes" onerror="continue" caching="yes">
DROP TABLE USERS;
DROP TABLE IMAGES;
DROP TABLE COMMENTS;
DROP TABLE FRIENDSHIP;
CREATE TABLE USERS (userid int not null generated always as
identity (start with 1, increment by 1), username char(255) not null,
password char(255), firstname char(255) not null, lastname char(255) not null, city char(255),
country char(255), text char(255), birthdate DATE not null, photofilename char(255), UNIQUE (username) );
CREATE TABLE IMAGES (imageid int not null generated always as
identity (start with 1, increment by 1), userid int not null, filename char(255) not null, insertdate timestamp not null,
CONSTRAINT userid_fk FOREIGN KEY(userid) REFERENCES USERS(userid) ON DELETE CASCADE);
CREATE TABLE COMMENTS (commentid int not null generated always as
identity (start with 1, increment by 1) PRIMARY KEY, fromuserid int, touserid int,
insertdate TIMESTAMP, text char(255),
CONSTRAINT fromuserid_fk FOREIGN KEY (fromuserid) REFERENCES USERS(userid) ON DELETE CASCADE,
CONSTRAINT touserid_fk FOREIGN KEY (touserid) REFERENCES USERS(userid) ON DELETE CASCADE);
CREATE TABLE FRIENDSHIP (fromuserid int, touserid int, state int, CONSTRAINT
fromuserid_fk FOREIGN KEY (fromuserid) REFERENCES USERS(userid) ON DELETE CASCADE,
CONSTRAINT touserid_fk FOREIGN KEY (touserid) REFERENCES USERS(userid) ON DELETE CASCADE);
</sql>
</target>

</project>

Runnando solo lo start o lo stop_server vedo che tutto fila liscio, ma quando lancio il test mi restituisce questo:


Buildfile: C:\Documents and Settings\elect\workspace\FirstLab\build.xml
test:

BUILD FAILED
C:\Documents and Settings\elect\workspace\FirstLab\build.xml:31: Class Not Found: JDBC driver lib/org.apache.derby.jdbc.EmbeddedDriver could not be loaded

Total time: 986 milliseconds


Ho googlato un pò, ma non ho trovato niente che facesse al caso mio.. ^^

Ho la strana sensazione che la soluzione sia molto semplice e veloce, ma non c'arrivo @.@, voi avete qualche idea? :)