Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Data.SqlClient;
- using System.Data;
- using Oracle.DataAccess.Client;
- namespace BD
- {
- class Program
- {
- public static OracleConnection RunOracle()
- {
- OracleConnection conn = new OracleConnection();
- String oradb = "Data Source=(DESCRIPTION=" +
- "(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=194.29.178.137)(PORT=1521)))"
- + "(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=ORCL)));"
- + "User Id=TEST3;Password=STUDENT;";
- try
- {
- conn = new OracleConnection(oradb);
- conn.Open();
- Console.WriteLine("Ustanowiono połączenie z bazą danych");
- }
- catch (Exception ex)
- {
- Console.WriteLine("{0}: Nie udało się połączyć", ex.Source);
- }
- return conn;
- }
- private static string GetSelectFromUser()
- {
- Console.WriteLine("\n\nPodaj select do wykonania:");
- return Console.ReadLine();
- }
- private static void ExecuteSelect(IDbConnection con, string str)
- {
- IDbCommand com = con.CreateCommand();
- com.CommandType = CommandType.Text;
- com.CommandText = str;
- AddRow(con, str);
- try
- {
- using (IDataReader reader = com.ExecuteReader())
- {
- int i = 0;
- while (reader.Read())
- {
- Console.WriteLine("\n" + reader[0] +"\n" + reader[1] + "\n" + reader[2] + "\n" + reader[3] + "\n\n----------------------------------------------------");
- i++;
- }
- }
- }
- catch (Exception ex)
- {
- Console.WriteLine("\nERROR\n{0}\n", ex.Message);
- }
- }
- private static void AddRow(IDbConnection con, string query)
- {
- IDbCommand com = con.CreateCommand();
- com.CommandType = CommandType.Text;
- string user = "194.29.178.147";
- try
- {
- string str = string.Format(@"INSERT INTO Qlog (QID,QDATE,QUERY,QUSER) VALUES (QLOG_SEQ.NEXTVAL,CURRENT_DATE,'{0}','{1}')", query, user);
- com.CommandText = str;
- com.ExecuteNonQuery();
- }
- catch (Exception ex)
- {
- Console.WriteLine("\nERROR\n{0}\n",ex.Message);
- }
- }
- static void Main(string[] args)
- {
- OracleConnection con = RunOracle();
- while (true)
- {
- string str = GetSelectFromUser();
- ExecuteSelect(con, str);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement