HSQLDB

hello i would ask you why the code below doesn't work (i recive an exception :

File input/output error: template.script in statement [SCRIPT 'template.script'] ):

Here is the code:

HSQLDBConnection.java

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.ResultSetMetaData;

import java.sql.SQLException;

import java.sql.Statement;

publicclass HSQLDBConnection{

Connection conn;

public HSQLDBConnection(String db_file_name_prefix,String user_name,String passwd)throws Exception{

//nawiazanie polaczenia z baza danych, jak nie ma jeszcze takiej to jest tworzona

Class.forName("org.hsqldb.jdbcDriver");

conn = DriverManager.getConnection("jdbc:hsqldb:"+ db_file_name_prefix,user_name,passwd);

}

publicvoid shutdown()throws SQLException{

//zamykanie polaczenia z baza danych

Statement st = conn.createStatement();

st.execute("SHUTDOWN");

conn.close();

}

//funkcji nalezy uzywac dla polecen typu SELECT

publicsynchronizedvoid query(String expression)throws SQLException{

Statement st =null;

ResultSet rs =null;

st = conn.createStatement();//wielokrotnego uzytku

rs = st.executeQuery(expression);//wykonaj polecenie

dump(rs);

st.close();

}

//funcji nalezy uzywac do polecen typu CREATE, DROP, INSERT lub UPDATE

publicsynchronizedvoid update(String expression)throws SQLException{

Statement st =null;

st = conn.createStatement();//wielokrotnego uzytku

int i = st.executeUpdate(expression);//wykonaj polecenie

if (i == -1){

System.out.println("db error : " + expression);

}

st.close();

}

publicstaticvoid dump(ResultSet rs)throws SQLException{

ResultSetMetaData meta= rs.getMetaData();

intcolmax = meta.getColumnCount();

inti;

Objecto =null;

for (; rs.next(); ){

for (i = 0; i < colmax; ++i){

o = rs.getObject(i + 1);

System.out.print(o.toString() +" ");

}

System.out.println(" ");

}

}

publicstaticvoid main(String[] args){

}

}

/code]

DBTemplateMaker.java

[code]

import java.io.*;

import java.sql.SQLException;

publicclass DBTemplateMaker{

private BufferedReader input;

private HSQLDBConnection db;

DBTemplateMaker(String templateFileName,HSQLDBConnection db){

this.db=db;

try{

db.query("SCRIPT '"+templateFileName+"");

}catch(SQLException ext2){

System.out.println("ect: "+ext2);

ext2.printStackTrace();

}

}

publicstaticvoid main (String []args){

}

}

dbTester.java

import java.sql.Connection;

import java.sql.SQLException;

publicclass dbTester{

private Connection conn;

public dbTester(){

HSQLDBConnection db =null;

try{

db =new HSQLDBConnection("db1_file","sa","");

}catch (Exception ex1){

ex1.printStackTrace();// could not start db

return;// bye bye

}

DBTemplateMaker dbtm=new DBTemplateMaker("./dbConnection/template.script",db);

}

publicstaticvoid main(String [] args){

dbTester dbt=new dbTester();

}

}

File template.script contains a lot of sql commands that makes some tables. I don;t know why it doesn't work . Probably i use SCRIPT command not as it should be used.

thanks for all replies

[7417 byte] By [polaka] at [2007-11-26 21:20:25]
# 1
"File input/output error" suggests to me that there is an error reading from that file. Perhaps it doesn't exist. (You are using a relative path -- is the server's working directory what you think it is?) Or perhaps there is something wrong with the name.
DrClapa at 2007-7-10 2:59:27 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2
Hmm i placed script file in main directory of project and in relative path :/so maybe it something diffrent?
polaka at 2007-7-10 2:59:27 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3
The obvious experiment would be to try using an absolute path.
DrClapa at 2007-7-10 2:59:27 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4
the same :/
polaka at 2007-7-10 2:59:27 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 5
maybe you can give me a small example where it is working?
polaka at 2007-7-10 2:59:27 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...