Гость
Целевая тема:
Создать новую тему:
Автор:
Форумы / Java [игнор отключен] [закрыт для гостей] / Определение причин невыполнения запроса / 8 сообщений из 8, страница 1 из 1
05.06.2013, 11:49:45
    #38286459
vladdv89
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Определение причин невыполнения запроса
Есть процедура, читающая из базы данных значения и записывающая данные в ArrayList-ы, которые также записываютмся в файлы. В результате выполнения программы отладочные файлы оказываются пустыми. Подскажите в чем дело Родключение к базе данных как я понимаю происходит поскольку файлы из блока catch SQLException не создаются. Почему не выполняется запрос? Как выяснить причину этого, если дело в этом.

Код: java
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143.
144.
145.
146.
147.
148.
149.
150.
151.
152.
153.
154.
155.
156.
157.
158.
159.
160.
161.
162.
163.
164.
		public void readUsingDataFromDatabase(ArrayList<String> therms, ArrayList<Integer> idOfFiles, ArrayList<Integer> countThermsInFiles, String[] url, String[] user, String[] password, int[] countFiles)
		{
			Connection con = null;
	 		Statement st = null;
        		ResultSet rs = null; 		
			String currentFile;
			int countThermsInFile;
			int countRows=0;
			try
			{
			   PrintWriter debugFileForBlock = null;
			   try
			   {
					debugFileForBlock = new PrintWriter(new FileOutputStream("/export/hadoop-1.0.1/bin/paramsinreadusingdata.txt"));
			   }
			   catch(FileNotFoundException e)
			   {
					System.exit(0);
			   }
			   debugFileForBlock.println(url[0]);
			   debugFileForBlock.println(user[0]);
			   debugFileForBlock.println(password[0]);
			   debugFileForBlock.close();			
				con = DriverManager.getConnection(url[0], user[0], password[0]);
	            		st = con.createStatement();
	            		rs = st.executeQuery("SELECT a.value, c.value, c.id FROM therms a INNER JOIN therm_occurs b ON b.therm_id = a.id INNER JOIN fs_entries c ON b.file_id = c.id ORDER BY a.value, c.value, c.id");
				rs.first();
				therms.add(rs.getString(1));
				countThermsInFile=1; 
				currentFile=rs.getString(2); 
				idOfFiles.add(rs.getInt(3)); 
			   PrintWriter debugFilePoint1 = null;
			   try
			   {
					debugFilePoint1 = new PrintWriter(new FileOutputStream("/export/hadoop-1.0.1/bin/point1.txt"));
			   }
			   catch(FileNotFoundException exc1)
			   {
					System.exit(0);
			   }
			   debugFilePoint1.println("Пройдена точка после позиционирования на первой записи");
			   debugFilePoint1.close();				
				countFiles[0]=1;
				countRows=1;
			   PrintWriter debugFilePoint2 = null;
			   try
			   {
					debugFilePoint2 = new PrintWriter(new FileOutputStream("/export/hadoop-1.0.1/bin/point2.txt"));
			   }
			   catch(FileNotFoundException exc2)
			   {
					System.exit(0);
			   }
			   debugFilePoint2.println("Пройдена точка после инициалиазции количества файлов и строк запроса единицами");
			   debugFilePoint2.close();				
				while (rs.next()) 
				{ 
					if (currentFile!=rs.getString(2)) 
						{
							countThermsInFiles.add(countThermsInFile); 
							countFiles[0]+=1; 
							currentFile=rs.getString(2); 
							countThermsInFile=1; 
							idOfFiles.add(rs.getInt(3)); 
						}
					else
						{
							countThermsInFile+=1; 
						}; 
					therms.add(rs.getString(1));
					countRows+=1;
				};
				countThermsInFiles.add(countThermsInFile);
			   PrintWriter debugFilePoint3 = null;
			   try
			   {
					debugFilePoint3 = new PrintWriter(new FileOutputStream("/export/hadoop-1.0.1/bin/point2.txt"));
			   }
			   catch(FileNotFoundException exc3)
			   {
					System.exit(0);
			   }
			   debugFilePoint3.println("Пройден цикл обхода по результатам запроса");
			   debugFilePoint3.close();	 
			}
			catch (SQLException e) 
			{
			   PrintWriter debugFileForException = null;
		          PrintWriter outFile = null; 			   		
			   try
			   {
					outFile = new PrintWriter(new FileOutputStream("/export/hadoop-1.0.1/bin/messagefromexception.txt"));
					debugFileForException = new PrintWriter(new FileOutputStream("/export/hadoop-1.0.1/bin/exception.txt"));
			   }
			   catch(FileNotFoundException ex)
			   {
					System.exit(0);
			   }
				StringWriter sw = new StringWriter();
				e.printStackTrace(new PrintWriter(sw));
				String exceptionAsString=sw.toString();
			   debugFileForException.println("Connection Failed! Check output console");
			   debugFileForException.println(exceptionAsString);
			   debugFileForException.close();			
				//System.out.println("Connection Failed! Check output console");
				//StringWriter sw = new StringWrite();
				//e.printStackTrace(new PrintWriter(sw));
				//String exceptionAsString=sw.toString();
				
			}
		   PrintWriter debugFileForRs = null;
		   PrintWriter debugFileForTherms = null;
		   PrintWriter debugFileForIds = null;
		   PrintWriter debugFileForCounts = null;
		   try
		   {
				debugFileForRs = new PrintWriter(new FileOutputStream("/export/hadoop-1.0.1/bin/resultset.txt"));
		   }
		   catch(FileNotFoundException e)
           		{
				System.exit(0);
           		}
		   debugFileForRs.println(countRows);
		   debugFileForRs.close();
		   try
		   {
				debugFileForTherms = new PrintWriter(new FileOutputStream("/export/hadoop-1.0.1/bin/therms.txt"));
		   }
		   catch(FileNotFoundException e)
           		{
				System.exit(0);
           		}
		   for (int i=0; i<therms.size(); i++)
		   {	 
				debugFileForTherms.println(therms.get(i));
		   }
		   debugFileForTherms.close();
           	   try
		   {
				debugFileForIds = new PrintWriter(new FileOutputStream("/export/hadoop-1.0.1/bin/idoffiles.txt"));
		   }
		   catch(FileNotFoundException e)
           		{
				System.exit(0);
           		}
		   for (int i=0; i<idOfFiles.size(); i++)
		   {	 
				debugFileForIds.println(idOfFiles.get(i));
		   }
		   debugFileForIds.close();
           	   try
		   {
				debugFileForCounts = new PrintWriter(new FileOutputStream("/export/hadoop-1.0.1/bin/countthermsinfiles.txt"));
		   }
		   catch(FileNotFoundException e)
           		{
				System.exit(0);
           		}
		   for (int i=0; i<countThermsInFiles.size(); i++)
		   {	 
				debugFileForCounts.println(countThermsInFiles.get(i));
		   }
		   debugFileForCounts.close();
		}
...
Рейтинг: 0 / 0
05.06.2013, 12:07:07
    #38286501
Petro123
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Определение причин невыполнения запроса
vladdv89,
пошаговая отладка
...
Рейтинг: 0 / 0
05.06.2013, 12:15:03
    #38286514
0FD
0FD
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Определение причин невыполнения запроса
vladdv89,

Сначала подумал что Вы JavaIO изучаете.
Почти уверен что вылетает здесь, на первом FileOutputStream, из-за того что нет прав на запись в /export
try {
debugFilePoint1 = new PrintWriter(new FileOutputStream("/export/hadoop-1.0.1/bin/point1.txt"));
} catch(FileNotFoundException exc1) {
System.exit(0);
}

Вы лучше System.out.println использовали
...
Рейтинг: 0 / 0
05.06.2013, 12:18:31
    #38286517
vladdv89
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Определение причин невыполнения запроса
0FD,

эти отладочные файлы потом были добавлены. Запрос выдает результаты в pgAdmin 3 (забыл сказать). Возможно не работает в программе.
...
Рейтинг: 0 / 0
05.06.2013, 12:20:11
    #38286522
vladdv89
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Определение причин невыполнения запроса
vladdv89,

Запрос выдает результаты в pgAdmin 3 (забыл сказать). Возможно не работает в программе.
...
Рейтинг: 0 / 0
05.06.2013, 12:29:55
    #38286546
0FD
0FD
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Определение причин невыполнения запроса
vladdv89,

Тогда присоединяюсь к Petro123, наставили кучу выводов в файлы и не знаете где происходит ошибка.
...
Рейтинг: 0 / 0
05.06.2013, 12:35:43
    #38286561
Определение причин невыполнения запроса
Поставьте внутри каждого catch (..) {
вызов e.printStackTrace() вместо или перед exit().

И не убирайте, пока не сможете объяснить более знающим людям, почему вам не нужно знать место и причину возникновения ошибки (а лучше вообще никогда не убирать - такое правило проще запомнить и сложнее будет встретить ошибку которая случается неизвестно где и непонятно почему).
...
Рейтинг: 0 / 0
05.06.2013, 13:03:14
    #38286621
Petro123
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Определение причин невыполнения запроса
vladdv89 Возможно не работает в программе.
у программистов есть отладка в IDE во втором тысячилетии.
...
Рейтинг: 0 / 0
Форумы / Java [игнор отключен] [закрыт для гостей] / Определение причин невыполнения запроса / 8 сообщений из 8, страница 1 из 1
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]