アットウィキロゴ

JDBCdf

package sql;

import java.sql.*;

class pro{
    
Connection dbx;  
Statement stx;  
String sqx;
ResultSet  rsx;

int key;

    public static void main(String [] args) {
        pro f=new pro();        
    }

pro(){

String url = "jdbc:derby:db;create=true";  
String usr = "";  
String pwd = "";

key=0;

try {  
dbx = DriverManager.getConnection(url, usr, pwd);
} catch (Exception ex) { ex.printStackTrace();}


if(key>50)createtable();

try {    
sqx="insert into tb8 values('BBBBB')";
stx = dbx.createStatement();
stx.executeUpdate(sqx);
stx.close();  

} catch (Exception ex) { ex.printStackTrace();}


try {  
stx = dbx.createStatement();
sqx="select * from tb8";  
rsx = stx.executeQuery(sqx);
if (rsx != null) {
while (rsx.next()) {
String x = rsx.getString("x1");
System.out.println(x);
}
}

rsx.close();
stx.close();
dbx.close();
    
} catch (Exception ex) {ex.printStackTrace();}




}
void createtable(){

try {  
sqx="create table tb8 (x1 long varchar)";
stx = dbx.createStatement();
stx.executeUpdate(sqx);
stx.close();  
} catch (Exception ex) { ex.printStackTrace();}


}

  
}
最終更新:2011年08月20日 08:17