Java/Database SQL JDBC/Cloudscape
Версия от 18:01, 31 мая 2010; (обсуждение)
Connect to 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();
}
}