4.1 ڵ3¸עȤreginterestINSERT_JAVASPʾ洢ݣԴ¡עȤֶRegIDProductNo


//򵥵JAVA洢
package mypackage;

import java.sql.*;

public class INSERT_JAVASP
{

public static void INSERT_JAVASP (String input1, String input2)
throws SQLException, Exception
{
int errorCode;

try
{
//÷ݿ
Connection con = DriverManager.getConnection("jdbc:default:connection");

String query = "INSERT INTO EBUSINES.reginterest (RegID, ProductNo)
VALUES (?, ?)";

PreparedStatement pstmt = con.prepareStatement(query);

pstmt.setString(1, input1); //1ʾSQLеĵ1

pstmt.setString(2, input2); //2ʾSQLеĵ2

pstmt.executeUpdate();

}

catch (SQLException sqle)
{
errorCode = sqle.getErrorCode();

throw new SQLException( errorCode + " FAILED" ); 
}

}

}

4.19 JavaӦóʵDB2ݿӵӡ
package mypackage;
import java.sql.*;
import java.util.*;
import java.io.*;
class test 
{
  public static void main(String args[])
  throws SQLException, Exception
  {
  
  try
  {
   Class.forName("COM.ibm.db2.jdbc.app.DB2Driver").newInstance();
   
   String url="jdbc:db2:EBUSINES"; //EBUSINESΪݿ
   String user="db2admin"; 
   String password="mydb2"; 
   Connection conn= DriverManager.getConnection(url,user,password);
   System.out.print("Done!OK!!!\n");
  }catch(SQLException sqle)
  {
   System.out.print(sqle); 
   }

  }
}

4.20 ͨDB2JDBCʵDB2ݿEBUSINESreginterestвݵӡ
package mypackage;

import java.sql.*;
import java.util.*;
import java.io.*;

public class INSERT_JAVASP
{
public static void INSERT_JAVASP (String input1, String input2)
throws SQLException, Exception
{
int errorCode;

try
{
//÷ݿ
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver").newInstance();
   
Connection conn = DriverManager.getConnection("jdbc:db2:EBUSINES","db2admin","mydb2");

String query = "INSERT INTO reginterest(RegID,ProductNo) VALUES(?,?)";

PreparedStatement pstmt = conn.prepareStatement(query);
pstmt.setString(1, input1); //1ʾSQLеĵ1
pstmt.setString(2, input2); //2ʾSQLеĵ2
pstmt.executeUpdate();
pstmt.close();
conn.close();
}
catch (SQLException sqle)
{
 System.out.print(sqle);
}
}
  public static void main(String args[])
 throws SQLException, Exception 
  {
    String input1="2", input2="001002";
    INSERT_JAVASP(input1,input2);
  }
}

4.22 ȽͨODBCDB2ݿ⣬ɺ4.19Ƶ
package mypackage;
import java.sql.*;
import java.util.*;
import java.io.*;

class test 
{
  public static void main(String args[])
  throws SQLException, Exception
  {
  
  try
  {
   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
   
   Connection conn =
DriverManager.getConnection("jdbc:odbc:ebusines","db2admin","mydb2");

   System.out.print("Done!OK!!!\n");
   
  }catch(SQLException sqle)
  {
   System.out.print(sqle); 
   }

  }
}

4.23 ͨODBCԴʵ4.20DB2ݿ
package mypackage;
import java.sql.*;
public class INSERT_JAVASP
{
public static void INSERT_JAVASP (String input1, String input2)
throws SQLException, Exception
{
int errorCode;
try
{
//÷ݿ
   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
   Connection conn =
DriverManager.getConnection("jdbc:odbc:ebusines","db2admin","mydb2");
String query = "INSERT INTO reginterest (RegID, ProductNo) VALUES (?, ?)";
PreparedStatement pstmt = conn.prepareStatement(query);
pstmt.setString(1, input1); //1ʾSQLеĵ1
pstmt.setString(2, input2); //2ʾSQLеĵ2
pstmt.executeUpdate();
}
catch (SQLException sqle)
{
errorCode = sqle.getErrorCode();
throw new SQLException( errorCode + " FAILED" ); 
}
}
  public static void main(String args[])
 throws SQLException, Exception 
  {
    String input1="1", input2="001001";
    INSERT_JAVASP(input1,input2);
  }
}