JDBC·Î DB¿¬°á¿¡¼­ À¥¿¡¼­¸¸ ¿¡·¯°¡


[ ´ÙÀ½ ±Ûµé ] [ À̾ ±Û¿Ã¸®±â(´äÇϱâ) ] [ ÀÚ¹Ù ¹¯°í ´äÇϱâ ]

±Û¾´ÀÌ :Á¶½ÅÁ¦ 1999³â 1¿ù 25ÀÏ 18:10:59

¾îÇø®ÄÉÀ̼ÇÀ¸·Î Â¥¸é DB¿¡ ¿¬°áÀÌ µÇ´Âµ¥
À¥¿¡¼­¸¸ ¾Æ·¡¿Í °°Àº ¿¡·¯°¡ ³ª¿ä.
Ȥ½Ã Informix DBMS »ç¿ëÇϽô ºÐ °è½Ã¸é Á» ºÁÁÖ¼¼¿ä.


ÇÁ·Î±×·¥ ¼Ò½º
import java.sql.*;
import java.util.*;
import java.applet.*;


public class Money extends Applet {


public void init()
{

String in_host = "jdbc:informix-sqli://210.126.14.1:";
String in_info = "/stores7:informixserver=ius;user=informix;password=informix";
// Æнº¿öµå´Â À§¿Í ´Ù¸¨´Ï´Ù.

String url = in_host + "1998" + in_info;

Connection conn = null;
int rc;
String cmd=null;
Statement stmt = null;


String testName = "Simple Select Statement";


System.out.println(">>>" + testName + " test.");
System.out.println("URL = \"" + url + "\"");


try
{
Class.forName("com.informix.jdbc.IfxDriver");
}
catch (Exception e)
{
System.out.println("ERROR: failed to load Informix JDBC driver.");
}



try
{
conn = DriverManager.getConnection(url);
}
catch (SQLException e)
{
System.out.println("ERROR: failed to connect!" + e);
}



try {
stmt=conn.createStatement();
cmd="drop table x;";
rc=stmt.executeUpdate(cmd);
}
catch (SQLException e)
{
System.out.println("Error:"+e.getMessage());
}
try
{
stmt = conn.createStatement();
cmd = "create table x(a char(20));";
rc = stmt.executeUpdate(cmd);
}
catch (SQLException e)
{
System.out.println("ERROR: execution failed - statement: " + cmd);
System.out.println("ERROR: " + e.getMessage());
}


try
{
// String name=ko2asc("ÀÎÆ÷¹Í½º");
String name="ÀÎÆ÷¹Í½º";
// name = name.replace("'","''");
cmd = "insert into x values ('"+name+"');";
rc = stmt.executeUpdate(cmd);
}
catch (SQLException e)
{
System.out.println("ERROR: execution failed - statement: " + cmd);
System.out.println("ERROR: " + e.getMessage());
}


/**
* Select Data from hoho table
*/
try{
String select="select * from x";
System.out.println(select);


PreparedStatement pstmt = conn.prepareStatement(select);
ResultSet rset = pstmt.executeQuery();
while(rset.next()){
// System.out.println(asc2ko(rset.getString(1)));
System.out.println(rset.getString(1));
}
rset.close();
pstmt.close();
}catch(SQLException e){
System.out.println("Failed to connect!");
}


try
{
conn.close();
}
catch (SQLException e)
{
System.out.println("ERROR: failed to close the connection!");
}


System.out.println(">>>End of " + testName + " test.");
}


public static String ko2asc(String str) {
String result = null;
try {
byte[] rawBytes = str.getBytes("KSC5601");
result = new String(rawBytes, "8859_1");
}
catch(java.io.UnsupportedEncodingException e) {
System.err.println(e.toString());
}
return result;
}
public static String asc2ko(String str) {
String result = null;
try {
byte[] rawBytes = str.getBytes("8859_1");
result = new String(rawBytes, "KSC5601");
}
catch(java.io.UnsupportedEncodingException e) {
System.err.println(e.toString());
}
return result;
}
}


¿¡·¯ ¸Þ½ÃÁö


>>>Simple Select Statement test.
URL = "jdbc:informix-sqli://210.126.14.1:1998/stores7:informixserver=ius;user=informix;password=eogksalsrnr"
ERROR: failed to connect!java.sql.SQLException: No suitable driver
java.lang.NullPointerException
at Money.init(Compiled Code)
* at netscape.applet.DerivedAppletFrame$InitAppletEvent.dispatch(Compiled Code)
at java.awt.EventDispatchThread$EventPump.dispatchEvents(Compiled Code)
at java.awt.EventDispatchThread.run(Compiled Code)
at netscape.applet.DerivedAppletFrame$AppletEventDispatchThread.run(Compiled Code)



´ÙÀ½ ±Ûµé:



À̾ ±Û¿Ã¸®±â(´äÇϱâ)

À̸§:
E-Mail:
Á¦¸ñ:
³»¿ë:
HTML ÅÂ±× Æ÷ÇÔ ¿©ºÎ: HTML ¹®¼­ÀÏ °æ¿ì üũ
°ü·Ã URL(¼±ÅÃ):
URL Á¦¸ñ(¼±ÅÃ):
°ü·Ã À̹ÌÁö URL:


[ ´ÙÀ½ ±Ûµé ] [ À̾ ±Û¿Ã¸®±â(´äÇϱâ) ] [ ÀÚ¹Ù ¹¯°í ´äÇϱâ ]