 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Mladen Adamovic Guest
|
Posted: Sat Dec 06, 2003 7:49 pm Post subject: need help using hsqldb |
|
|
I made database photo and put it into /photo dir.
hSQLdb ScriptTool did photo.properties, photo.script and photo.data(0
bytes).
In photo.script I have:
<snip>
CREATE TABLE LOCALIZATION(ID INTEGER NOT NULL PRIMARY KEY,DESCRIPTION
CHAR(50),ENG CHAR(200),GER CHAR(200),FRE CHAR(200),ITA CHAR(200),POR
CHAR(200),SER CHAR(200),SPA CHAR(200))
<snip>
INSERT INTO LOCALIZATION
VALUES(6,'Format','Format','Format','Format','Configurazione','Formato','For
mat','El formato')
<snip>
And I have following problem : In Java I connect to the hsqldb database,
execute simple query select * from localization and
got No data is available (in the ResultSet object).
I did class Problem which is small class representing problem I have, and
when I run it:
C:photo>java -classpath /hsqldb/lib/hsqldb.jar;. Problem
c:org.hsqldb.jdbcConnection@147c5fc
Exception : No data is available
java.sql.SQLException: No data is available
at org.hsqldb.Trace.getError(Unknown Source)
at org.hsqldb.Trace.error(Unknown Source)
at org.hsqldb.jdbcResultSet.checkAvailable(Unknown Source)
at org.hsqldb.jdbcResultSet.getColumnInType(Unknown Source)
at org.hsqldb.jdbcResultSet.getInt(Unknown Source)
at Problem.init(Problem.java:73)
at Problem.<init>(Problem.java:55)
at Problem.main(Problem.java:93)
Now follows Problem.java SOURCE CODE:
---------------------------------------------------------------------<cut
here: Problem.java>
import java.sql.*;
import java.io.*;
import java.util.*;
public class Problem
{
public String SQLServer="hSQLdb";
public String MySqlDriverName="com.mysql.jdbc.Driver";
public String hSQLdbDriverName="org.hsqldb.jdbcDriver";
public String
MySqlDbURL="jdbc:mysql://localhost/photo?user=guest&password=guest";
public String hSQLdbURL="jdbc:hsqldb:/photo/photo";
public String hSQLdbUser="sa";
public String hSQLdbPass="";
Connection con;
String mem_id;
String language;
Statement selectStmt;
ResultSet rs;
int langNo,translLength;
static String[][] transl=new String[500][10];
public Connection getConnection()
{
Connection c;
try
{
if(SQLServer.toUpperCase().equals("HSQLDB"))
{
Class.forName (hSQLdbDriverName);
c = DriverManager.getConnection (hSQLdbURL, hSQLdbUser, hSQLdbPass);
System.out.println("c:"+c);
return c;
}
else
{
System.out.println("Error in SQLServer name.");
System.exit(0);
}
}
catch (Exception e) {
System.out.println("ERROR: failed to load HSQLDB JDBC driver.");
e.printStackTrace(); }
return null;
}
/**
* constructor for english language
*/
public Problem()
{
//connect to the database where information of orders are stored
con=getConnection();
init();
}
void init()
{
int no=0;
translLength=0;
try
{
selectStmt=con.createStatement();
rs=selectStmt.executeQuery(
"select id,description,eng,ger,fre,ita,por,ser,spa from
localization");
do
{
//rs.first(); //IF I uncomment this line I GOT
//Exception : ResultSet was set to forward only
no=rs.getInt(1); //IN THIS LINE I GOT EXCEPTION
transl[no][0]=rs.getString(2); //description
transl[no][1]=rs.getString(3); //english
transl[no][2]=rs.getString(4); //german
transl[no][3]=rs.getString(5); //french
transl[no][4]=rs.getString(6); //italian
transl[no][5]=rs.getString(7); //portuguese
transl[no][6]=rs.getString( ; //serbian
transl[no][7]=rs.getString(9); //spain
if(no>translLength) translLength=no;
System.err.println(transl[no][0]+transl[no][1]+transl[no][2]+transl[no][3]+
transl[no][4]+transl[no][5]+transl[no][6]+transl[no][7]);
} while(rs.next());
} catch(Exception e)
{ System.err.println("Exception : "+e.getMessage());
e.printStackTrace();
}
}
public static void main(String[] args)
{
Problem p=new Problem();
//p.run();
}
}
---------------------------------------------------------------------<cut
here: Problem.java>
Please help me.
If somebody want, I can send photo.* database files by email for easier (and
IMHO very easy for experienced hsqldb programers) resolving the problem.
Thanks in advance.
|
|
| Back to top |
|
 |
Herman Timmermans Guest
|
Posted: Sun Dec 07, 2003 6:40 am Post subject: Re: need help using hsqldb |
|
|
Mladen Adamovic wrote:
| Quote: | I made database photo and put it into /photo dir.
hSQLdb ScriptTool did photo.properties, photo.script and photo.data(0
bytes).
In photo.script I have:
snip
CREATE TABLE LOCALIZATION(ID INTEGER NOT NULL PRIMARY KEY,DESCRIPTION
CHAR(50),ENG CHAR(200),GER CHAR(200),FRE CHAR(200),ITA CHAR(200),POR
CHAR(200),SER CHAR(200),SPA CHAR(200))
snip
INSERT INTO LOCALIZATION
VALUES(6,'Format','Format','Format','Format','Configurazione','Formato','For
mat','El formato')
snip
And I have following problem : In Java I connect to the hsqldb database,
execute simple query select * from localization and
got No data is available (in the ResultSet object).
I did class Problem which is small class representing problem I have, and
when I run it:
C:photo>java -classpath /hsqldb/lib/hsqldb.jar;. Problem
c:org.hsqldb.jdbcConnection@147c5fc
Exception : No data is available
java.sql.SQLException: No data is available
at org.hsqldb.Trace.getError(Unknown Source)
at org.hsqldb.Trace.error(Unknown Source)
at org.hsqldb.jdbcResultSet.checkAvailable(Unknown Source)
at org.hsqldb.jdbcResultSet.getColumnInType(Unknown Source)
at org.hsqldb.jdbcResultSet.getInt(Unknown Source)
at Problem.init(Problem.java:73)
at Problem.<init>(Problem.java:55)
at Problem.main(Problem.java:93)
Now follows Problem.java SOURCE CODE:
---------------------------------------------------------------------<cut
here: Problem.java
import java.sql.*;
import java.io.*;
import java.util.*;
public class Problem
{
public String SQLServer="hSQLdb";
public String MySqlDriverName="com.mysql.jdbc.Driver";
public String hSQLdbDriverName="org.hsqldb.jdbcDriver";
public String
MySqlDbURL="jdbc:mysql://localhost/photo?user=guest&password=guest";
public String hSQLdbURL="jdbc:hsqldb:/photo/photo";
public String hSQLdbUser="sa";
public String hSQLdbPass="";
Connection con;
String mem_id;
String language;
Statement selectStmt;
ResultSet rs;
int langNo,translLength;
static String[][] transl=new String[500][10];
public Connection getConnection()
{
Connection c;
try
{
if(SQLServer.toUpperCase().equals("HSQLDB"))
{
Class.forName (hSQLdbDriverName);
c = DriverManager.getConnection (hSQLdbURL, hSQLdbUser, hSQLdbPass);
System.out.println("c:"+c);
return c;
}
else
{
System.out.println("Error in SQLServer name.");
System.exit(0);
}
}
catch (Exception e) {
System.out.println("ERROR: failed to load HSQLDB JDBC
driver.");
e.printStackTrace(); }
return null;
}
/**
* constructor for english language
*/
public Problem()
{
//connect to the database where information of orders are stored
con=getConnection();
init();
}
void init()
{
int no=0;
translLength=0;
try
{
selectStmt=con.createStatement();
rs=selectStmt.executeQuery(
"select id,description,eng,ger,fre,ita,por,ser,spa from
localization");
do
{
//rs.first(); //IF I uncomment this line I GOT
//Exception : ResultSet was set to forward only
no=rs.getInt(1); //IN THIS LINE I GOT EXCEPTION
transl[no][0]=rs.getString(2); //description
transl[no][1]=rs.getString(3); //english
transl[no][2]=rs.getString(4); //german
transl[no][3]=rs.getString(5); //french
transl[no][4]=rs.getString(6); //italian
transl[no][5]=rs.getString(7); //portuguese
transl[no][6]=rs.getString( ; //serbian
transl[no][7]=rs.getString(9); //spain
if(no>translLength) translLength=no;
System.err.println(transl[no][0]+transl[no][1]+transl[no][2]+transl[no][3]+
transl[no][4]+transl[no][5]+transl[no][6]+transl[no][7]);
} while(rs.next());
} catch(Exception e)
{ System.err.println("Exception : "+e.getMessage());
e.printStackTrace();
}
}
public static void main(String[] args)
{
Problem p=new Problem();
//p.run();
}
}
---------------------------------------------------------------------
here: Problem.java
Please help me.
If somebody want, I can send photo.* database files by email for easier
(and IMHO very easy for experienced hsqldb programers) resolving the
problem. Thanks in advance.
********************************************************** |
I think you should use rs.next() to position the resultset to the first
record. So you need to change your code to do something lie
while (rs.next()){
//do something
};
Hope this helps,
Brgds Herman
--
Suse Linux Professional 8.1 on Athlon 1.1 Ghz 512 Mb
Anti Spam = remove the "dot" and the "at"
Registered Linux User #264690
|
|
| Back to top |
|
 |
Mladen Adamovic Guest
|
Posted: Sun Dec 07, 2003 9:20 am Post subject: Re: need help using hsqldb |
|
|
Now my program works. Thank to gnazio and Herman Timmermans, for the really
fast help.
"gnazio" <usenet.user (AT) email (DOT) it> wrote:
| Quote: | "Mladen Adamovic" <adamm (AT) blic (DOT) net> wrote
[CUT]
And I have following problem : In Java I connect to the hsqldb database,
execute simple query select * from localization and
got No data is available (in the ResultSet object).
[CUT]
I think that this is not an hsqldb problem.
When you get your ResultSet the cursor isn't set on the first row.
The first thing you have to do is to call next() on your ResultSet.
If you use a
do {
...
} while(rs.next());
you'll get an exeception on the firse rs.getXXX because the cursor is
pointing nothing.
Modify your code using a
while(rs.next()) {
...
}
and it'll work.
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|