Cloudscape Database Connections

From Java Example Source Code

Jump to: navigation, search

Contents

[edit] Overview - Cloudscape Database Connections

This Java example program introduces Cloudscape Database Connections.

[edit] Java Source Code

  • Package: example.cloudscape
  • File: MainClass.java
package example.cloudscape;
 
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
 
public class MainClass {
    public MainClass() {
	try {
	    Class.forName("COM.cloudscape.core.RmiJdbcDriver");
	    Connection connection = DriverManager.getConnection("jdbc:cloudscape:rmi:books");
	    Statement statement = connection.createStatement();
	    ResultSet resultSet = statement.executeQuery("SELECT * FROM authors");
	    ResultSetMetaData metaData = resultSet.getMetaData();
	    int numberOfColumns = metaData.getColumnCount();
 
	    for (int i = 1; i <= numberOfColumns; i++) {
		System.out.println(metaData.getColumnName(i) + "\t");
	    }
 
	    while (resultSet.next()) {
 
		for (int i = 1; i <= numberOfColumns; i++) {
		    System.out.println(resultSet.getObject(i) + "\t");
		}
 
		System.out.println("\n");
	    }
 
	    statement.close();
	    connection.close();
	} catch (SQLException sqlException) {
	    System.out.println(sqlException.getMessage());
	} catch (ClassNotFoundException classNotFound) {
	    System.out.println("Driver Not Found");
	    System.exit(1);
	}
    }
 
    public static void main(String args[]) {
	new MainClass();
    }
}

[edit] What Result You Can Get

Coming soon...

[edit] Required External Libraries and/or Files for this Java Example

In order to run this Java example, one of the following libraries may be required: In order to run this example program, one of the following libraries may be required:


[edit] How to Run this Java Example Program

We recommend running this Java example program with Eclipse.

For assistance in working with Eclipse, please see How to Run Java Program with Eclipse.

It's fairly easy.



[edit] Question & Answer

Any question?

Click edit and post your question or answer here.


Personal tools