반응형
자바 소스
[code type="java"]
import java.sql.*;

public class CallableTest {
public static void main(String[] args) throws SQLException{
  Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/mysql", "root", "apmsetup");
  
  PreparedStatement stmt;
  
  String sqlStr = "select * from db where id=?";
  
  stmt = conn.prepareStatement(sqlStr);
  
  stmt.setInt(1, 10);
  
  ResultSet rs = stmt.executeQuery();
  
  while(rs.next())
  {
   System.out.println(rs.getString(1));
  }
  
  stmt.close();
  conn.close();
 }
}
[/code]

=======================================
그리고 C# 소스
[code type="csharp"]
using System;
using System.Data;
using System.Data.SqlClient;

class SqlParamTest
{
    static void Main(string[] args)
    {
        string connStr = "Provider=MySQLProv;Data Source=mysql;" +
                         "Location=localhost;User Id=root;Password=apmsetup";
        string query = "select * from db where id=@ID";

        SqlConnection conn = new SqlConnection(connStr);
        conn.Open();

        SqlCommand comm = new SqlCommand(query, conn);

        comm.Parameters.Add("@ID", SqlDbType.Int);
        comm.Parameters["@ID"].Value = "10";

        SqlDataReader sr = comm.ExecuteReader();

        while (sr.Read())
        {
            Console.WriteLine(sr.GetInt32(0)));
        }
        sr.Close();
        conn.Close();
    }
}
[/code]

+ Recent posts