Hi,friends
In order to test the JDBC performance i wrote a small java application below.(The JDK is 1.3.1)
[DbTest.java]
import java.util.*;
import DatabaseOperation;
public class DbTest {
public static void main(String[] args) {
try {
DatabaseOperation DbOper;
DbOper = new DatabaseOperation();
Date startTime = new Date();
DbOper.executeQuery("select * from fc_room"
Date stopTime = new Date();
Date lapsedTime = new Date(stopTime.getTime() - startTime.getTime());
System.out.println("Total cost=" + lapsedTime.getMinutes()+"m:" + lapsedTime.getSeconds()+"s"
DbOper.executeClose();
}
catch(Exception e) {
System.err.println("Why:"+e.getMessage());
}
}
}
[DatabaseOperation.java]
import java.sql.*;
public class DatabaseOperation {
String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String sConnStr = "jdbcdbc:jboss_odbc";
Connection conn;
ResultSet rs;
Statement stmt;
public DatabaseOperation() {
try {
Class.forName(sDBDriver);
}
catch(java.lang.ClassNotFoundException e) {
System.err.println("sql_data():"+e.getMessage());
}
}
public void executeInsert(String sql) {
try {
conn = DriverManager.getConnection(sConnStr,"ihpms","ihpms"
Statement stmt= conn.createStatement();
stmt.executeUpdate(sql);
}
catch(SQLException ex) {
System.err.println("sql_data.executeUpdate:"+ex.getMessage());
}
}
public ResultSet executeQuery(String sql) {
rs = null;
try {
conn = DriverManager.getConnection(sConnStr,"ihpms","ihpms"
Statement stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}
catch(SQLException ex) {
System.err.println("sql_data.executeQuery:"+ex.getMessage());
}
return rs;
}
public void executeDelete(String sql) {
try {
conn = DriverManager.getConnection(sConnStr,"ihpms","ihpms"
Statement stmt = conn.createStatement();
stmt.executeUpdate(sql);
}
catch(SQLException ex) {
System.err.println("sql_data.executeDelete:"+ex.getMessage());
}
}
public void executeUpdate(String sql) {
try {
conn = DriverManager.getConnection(sConnStr,"ihpms","ihpms"
Statement stmt = conn.createStatement();
stmt.executeUpdate(sql);
}
catch(SQLException ex) {
System.err.println("sql_data.executeDelete:"+ex.getMessage());
}
}
public void executeClose() {
try {
stmt.close();
conn.close();
rs.close();
}
catch(Exception ex) {
System.out.println(ex.toString());
}
}
}
The compile is ok but when i run it by java DbTest
java.lang.NullPointerException is raised!
Using jdb i found in DatabaseOperation.executeQuery method the stmt is null(the conn has value assigned).
Hope i can get helps from all of you.Thanks! IPO_z@cmmail.com
Garbage in,Garbage out
In order to test the JDBC performance i wrote a small java application below.(The JDK is 1.3.1)
[DbTest.java]
import java.util.*;
import DatabaseOperation;
public class DbTest {
public static void main(String[] args) {
try {
DatabaseOperation DbOper;
DbOper = new DatabaseOperation();
Date startTime = new Date();
DbOper.executeQuery("select * from fc_room"
Date stopTime = new Date();
Date lapsedTime = new Date(stopTime.getTime() - startTime.getTime());
System.out.println("Total cost=" + lapsedTime.getMinutes()+"m:" + lapsedTime.getSeconds()+"s"
DbOper.executeClose();
}
catch(Exception e) {
System.err.println("Why:"+e.getMessage());
}
}
}
[DatabaseOperation.java]
import java.sql.*;
public class DatabaseOperation {
String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String sConnStr = "jdbcdbc:jboss_odbc";
Connection conn;
ResultSet rs;
Statement stmt;
public DatabaseOperation() {
try {
Class.forName(sDBDriver);
}
catch(java.lang.ClassNotFoundException e) {
System.err.println("sql_data():"+e.getMessage());
}
}
public void executeInsert(String sql) {
try {
conn = DriverManager.getConnection(sConnStr,"ihpms","ihpms"
Statement stmt= conn.createStatement();
stmt.executeUpdate(sql);
}
catch(SQLException ex) {
System.err.println("sql_data.executeUpdate:"+ex.getMessage());
}
}
public ResultSet executeQuery(String sql) {
rs = null;
try {
conn = DriverManager.getConnection(sConnStr,"ihpms","ihpms"
Statement stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}
catch(SQLException ex) {
System.err.println("sql_data.executeQuery:"+ex.getMessage());
}
return rs;
}
public void executeDelete(String sql) {
try {
conn = DriverManager.getConnection(sConnStr,"ihpms","ihpms"
Statement stmt = conn.createStatement();
stmt.executeUpdate(sql);
}
catch(SQLException ex) {
System.err.println("sql_data.executeDelete:"+ex.getMessage());
}
}
public void executeUpdate(String sql) {
try {
conn = DriverManager.getConnection(sConnStr,"ihpms","ihpms"
Statement stmt = conn.createStatement();
stmt.executeUpdate(sql);
}
catch(SQLException ex) {
System.err.println("sql_data.executeDelete:"+ex.getMessage());
}
}
public void executeClose() {
try {
stmt.close();
conn.close();
rs.close();
}
catch(Exception ex) {
System.out.println(ex.toString());
}
}
}
The compile is ok but when i run it by java DbTest
java.lang.NullPointerException is raised!
Using jdb i found in DatabaseOperation.executeQuery method the stmt is null(the conn has value assigned).
Hope i can get helps from all of you.Thanks! IPO_z@cmmail.com
Garbage in,Garbage out