BBS水木清华站∶精华区

发信人: wupopo (wupopo), 信区: Java 
标  题: 关于Java通过JDBC访问数据库的完全解决方案--example 
发信站: BBS 水木清华站 (Fri May 12 01:22:40 2000) WWW-POST 
 
oracle: 
public String InsertMember  ( 
byte[] p_address 

try{ 
p_address="'"+p_address+"'"; 
 
strSQL="insert into Member (address) values("; 
 
strSQL+=p_address 
 
java.sql.Connection conn =DriverManager.getConnection (strConnectionURL,str 
UserName, strPassWord); 
stmt= conn.createStatement(); 
 
if(stmt.executeUpdate(strSQL)>=0) 
System.out.println("ok"); 
else 
System.out.println("no"); 
stmt.executeUpdate("commit"); 
 
stmt.close(); 
conn.close(); 
return strRt; 
}    catch(Exception e){ 
//  stmt.executeUpdate("rollback"); 
e.printStackTrace(); 
return null; 

 

 
sql server: 
public static  boolean insertTest1(int xh,String xm) throws Exception{ 
     try{ 
      
      
     java.sql.Connection conn =DriverManager.getConnection ("jdbc:odbc:fiss", 
"sa", "sa"); 
PreparedStatement stmt= conn.prepareStatement("insert into test(xh,xm)  
values(?,?)"); 
     
stmt.setInt(1,xh); 
 
stmt.setBytes(2,xm.getBytes("GBK")); 
stmt.execute(); 
stmt.close(); 
conn.close(); 
return true; 
 
}    catch(Exception e){ 
e.printStackTrace(); 
return false; 
 

      
    } 
 
-- 
※ 来源:·BBS 水木清华站 smth.org·[FROM: 202.108.21.142]  

BBS水木清华站∶精华区