aspose file tools
The moose likes JDBC and Relational Databases and the fly likes Not able to start the Hibernate DB server. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Not able to start the Hibernate DB server." Watch "Not able to start the Hibernate DB server." New topic

Not able to start the Hibernate DB server.

rahul deo

Joined: Jul 05, 2011
Posts: 10

I am new to Hibernate. I have downloaded file. I have added hsqldb.jar in build path of application and tried to run this file and getting below as an exception. Please help.

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;

* Title: Testdb
* Description: simple hello world db example of a
* standalone persistent db application
* every time it runs it adds four more rows to sample_table
* it does a query and prints the results to standard out
* Author: Karl Meissner
public class Testdb {

Connection conn; //our connnection to the db - presist for life of program

// we dont want this garbage collected until we are done
public Testdb(String db_file_name_prefix) throws Exception { // note more general exception

// Load the HSQL Database Engine JDBC driver
// hsqldb.jar should be in the class path or made part of the current jar

// connect to the database. This will load the db files and start the
// database if it is not alread running.
// db_file_name_prefix is used to open or create files that hold the state
// of the db.
// It can contain directory names relative to the
// current working directory
conn = DriverManager.getConnection("jdbc:hsqldb:"
+ db_file_name_prefix, // filenames
"sa", // username
""); // password

public void shutdown() throws SQLException {

Statement st = conn.createStatement();

// db writes out to files and performs clean shuts down
// otherwise there will be an unclean shutdown
// when program ends
conn.close(); // if there are no other open connection

// use for SQL command SELECT
public synchronized void query(String expression) throws SQLException {

Statement st = null;
ResultSet rs = null;

st = conn.createStatement(); // statement objects can be reused with

// repeated calls to execute but we
// choose to make a new one each time
rs = st.executeQuery(expression); // run the query

// do something with the result set.
st.close(); // NOTE!! if you close a statement the associated ResultSet is

// closed too
// so you should copy the contents to some other object.
// the result set is invalidated also if you recycle an Statement
// and try to execute some other query before the result set has been
// completely examined.

// use for SQL commands CREATE, DROP, INSERT and UPDATE
public synchronized void update(String expression) throws SQLException {

Statement st = null;

st = conn.createStatement(); // statements

int i = st.executeUpdate(expression); // run the query

if (i == -1) {
System.out.println("db error : " + expression);

} // void update()

public static void dump(ResultSet rs) throws SQLException {

// the order of the rows in a cursor
// are implementation dependent unless you use the SQL ORDER statement
ResultSetMetaData meta = rs.getMetaData();
int colmax = meta.getColumnCount();
int i;
Object o = null;

// the result set is a cursor into the data. You can only
// point to one row at a time
// assume we are pointing to BEFORE the first row
// points to next row and returns true
// or false if there is no next row, which breaks the loop
for (;; ) {
for (i = 0; i < colmax; ++i) {
o = rs.getObject(i + 1); // Is SQL the first column is indexed

// with 1 not 0
System.out.print(o.toString() + " ");

System.out.println(" ");
} //void dump( ResultSet rs )

public static void main(String[] args) {

Testdb db = null;

try {
db = new Testdb("db_file");
} catch (Exception ex1) {
ex1.printStackTrace(); // could not start db

return; // bye bye

try {

//make an empty table
// by declaring the id column IDENTITY, the db will automatically
// generate unique values for new rows- useful for row keys
"CREATE TABLE sample_table ( id INTEGER IDENTITY, str_col VARCHAR(256), num_col INTEGER)");
} catch (SQLException ex2) {

//ex2.printStackTrace(); // second time we run program
// should throw execption since table
// already there
// this will have no effect on the db

try {

// add some rows - will create duplicates if run more then once
// the id column is automatically generated
"INSERT INTO sample_table(str_col,num_col) VALUES('Ford', 100)");
"INSERT INTO sample_table(str_col,num_col) VALUES('Toyota', 200)");
"INSERT INTO sample_table(str_col,num_col) VALUES('Honda', 300)");
"INSERT INTO sample_table(str_col,num_col) VALUES('GM', 400)");

// do a query
db.query("SELECT * FROM sample_table WHERE num_col < 250");

// at end of program
} catch (SQLException ex3) {
} // main()

Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version number in .class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(
at Method)
at java.lang.ClassLoader.loadClass(
at sun.misc.Launcher$AppClassLoader.loadClass(
at java.lang.ClassLoader.loadClass(
at java.lang.ClassLoader.loadClassInternal(
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(
at Testdb.<init>(
at Testdb.main(

Thanks in advance.
Christian Dillinger
Ranch Hand

Joined: Jul 20, 2009
Posts: 189
That's not Hibernate. That's pure JDBC. The error tells you, that your class-File is "newer" than your version of java.exe. Seems you are trying to run an application compiled with (e.g.) Java 6 on a Java 5 JVM. Or Java 7 on JVM 6.
I agree. Here's the link:
subject: Not able to start the Hibernate DB server.