(1)
Import ifxjdbc.jar
(2) import java.sql.*;
(3) 注意連線字串
(4) 範例程式
package hhh;
import java.sql.*;
public class hahah {
public static void main(String[] args) {
// TODO Auto-generated method stub
Connection conn = null;
Statement statement = null;
ResultSet resultSet = null;
String dbURL = "jdbc:informix-sqli://Host:port/database name:informixserver=servername;"
+ "DB_LOCALE=zh_tw.big5;user=帳號;password=密碼;";
+ "DB_LOCALE=zh_tw.big5;user=帳號;password=密碼;";
try {
//測試連線
Class.forName("com.informix.jdbc.IfxDriver");
System.out.println("Driver OK");
conn =DriverManager.getConnection(dbURL);
System.out.println("connection OK");
Statement query = null;
ResultSet rs = null;
try
{
query = conn.createStatement();
rs = query.executeQuery("SELECT * FROM TableName WHERE 條件= 'xxx'");
while (rs.next())
{
System.out.println(rs.getString(0));
}
rs.close();
query.close();
}
catch (SQLException exce)
{
System.out.println("Caught: " + exce.getErrorCode());
}
conn.close();
}
catch (ClassNotFoundException drvEx)
{
System.err.println("Could not load JDBC driver");
System.out.println("Exception: " + drvEx);
drvEx.printStackTrace();
}
catch(SQLException sqlEx)
{
while(sqlEx != null)
{
System.err.println("SQLException information");
System.err.println("Error msg: " + sqlEx.getMessage());
System.err.println("SQLSTATE: " + sqlEx.getSQLState());
System.err.println("Error code: " + sqlEx.getErrorCode());
sqlEx.printStackTrace();
sqlEx=sqlEx.getNextException();
}
}
}
}