📄 example3.java
字号:
/*
* WebLogic Server Unleashed
*
*/
package com.wlsunleashed.jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
/**
* This class demonstrates an SQL SELECT using a Connection object.
*
* @version 1.0
*/
public class Example3 {
/**
* The main method - the point of entry into this class
*
* @param args : all run-time args are passed in this String array
*/
public static void main(String[] args) {
Example3 obj = new Example3();
obj.fetchITEMtable();
}
/**
* Returns a connection to a pointbase database, whose server is running at
* the given host and port, and the database being called dbName. The
* credentials supplied while connecting is also accepted as paramter
*
* @param host : The host where the server is running
* @param port : The port where the server is listening to
* @param dbName : The database name
* @param userid : The user id to use while connecting
* @param password : The password of the specified user
*
* @return An object of type java.sql.Connection
*/
private Connection getConnection(
String host,
int port,
String dbName,
String userid,
String password) {
Connection conn = null;
try {
Class.forName("com.pointbase.jdbc.jdbcUniversalDriver");
String url =
"jdbc:pointbase:server://" + host + ":" + port + "/" + dbName;
System.out.println("Using url string " + url);
conn = DriverManager.getConnection(url, userid, password);
System.out.println("Obtained Connection");
} catch (Throwable t) {
t.printStackTrace();
conn = null;
}
return conn;
}
/**
* fetches all the rows of the ITEM table and prints it out.
*/
private void fetchITEMtable() {
System.out.println("Trying to obtain a connection ... ");
Connection conn =
getConnection(
"localhost",
9092,
"demo",
"PBSYSADMIN",
"PBSYSADMIN");
if (conn == null) {
return;
}
System.out.println("Connection obtained !");
String anSQLStmt = " SELECT * FROM XYZCONF.ITEM ";
try {
System.out.println("Executing statement : " + anSQLStmt);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(anSQLStmt);
int row = 1;
while (rs.next()) {
int fld = 1;
System.out.println(
"Row #"
+ row++
+ ", id = "
+ rs.getInt(fld++)
+ ", desc = "
+ rs.getString(fld++)
+ ", stock = "
+ rs.getInt(fld++)
+ ", unit price = "
+ rs.getDouble(fld++));
}
rs.close();
stmt.close();
conn.close();
} catch (Throwable t) {
t.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -