Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/jcmouse/public_html/app/code/include/model/database/db.class.php on line 18

Deprecated: Function eregi_replace() is deprecated in /home/jcmouse/public_html/app/code/include/model/database/pregunta.php on line 161

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/jcmouse/public_html/app/code/include/model/database/db.class.php on line 18
Ayuda con Analizador de Sentencias SQL ("select") en - Code Army!
Te encuentras en el foro de Java

Ayuda con Analizador de Sentencias SQL ("select") en


Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/jcmouse/public_html/app/code/include/model/database/db.class.php on line 18
problem
06/10/2013 05:43
Th3Pho3Nix
Rango: Soldado
06/10/2013 05:26
Guatemala
1
0
Fecha de ingreso
Ubicacion
Preguntas
Respuestas

Hola amigos...queria ver si no me echan una mano, con un proyecto para la universidad, la cosa es que con un archivo de entrada, en el cual van a estar las sentencias de SQL, en realidad solo la "select", pero son varias, asi:
select * from Facturas;
select code,nombre from Clientes;
pero tambien hay sentencias erroneas, para probar si el programa las detecta
select from Alumno

tambien tengo 2 archivos: uno llamado Facturas.txt y el otro Clientes.txt.
Entonces despues de revisar si la gramatica de las sentencias SQL estan correctas, se deben ejecuatar dichas sentencias correctas, de esta manera, por ejemplo en el archivo de entrada hay una linea asi:
select code,nombre from Clientes;
por lo cual se debe ir al archivo Clientes.txt y extraer las columnas code y nombre, para luego ser mostrados en pantalla....
les dejo un codigo que he estado haciendo...esta mal...pero con algo se empieza no???

  1. package proyec_2;
  2. import java.io.BufferedReader;
  3. import java.io.File;
  4. import java.io.FileNotFoundException;
  5. import java.io.FileReader;
  6. import java.io.FileWriter;
  7. import java.io.IOException;
  8. import java.util.ArrayList;
  9. import java.util.StringTokenizer;
  10. import java.util.logging.Level;
  11. import java.util.logging.Logger;
  12.  
  13. public class SQL
  14. {
  15. ArrayList Abr = new ArrayList();
  16. ArrayList Abr2 = new ArrayList();
  17. ArrayList CL = new ArrayList();
  18. String s1,c,CC,ss2;
  19. String s2,Campo;
  20. ArrayList MTX = new ArrayList();
  21. ArrayList DAT = new ArrayList();
  22. ArrayList DT = new ArrayList();
  23. ArrayList DAT_to_Print = new ArrayList();
  24. String matrix[][]=new String[40][2];
  25. String s,D;
  26. String SS;
  27. int id=0;
  28. public void AN_SQL() throws FileNotFoundException
  29. {
  30. // Cargamos el buffer con el contenido del archivo
  31. try{
  32. BufferedReader br = new BufferedReader (new FileReader ("archivo_prueba.txt"));
  33.  
  34. // Leemos la primera linea
  35.  
  36. while((s1 = br.readLine())!=null){
  37.  
  38. // System.out.println ("La primera linea del archivo es: " + s1);
  39. // System.out.println ("La linea tiene " + s1.length() + " caracteres");
  40. //
  41. // System.out.println ();
  42. // System.out.println ("Separando la linea en trozos tenemos las siguientes palabras:");
  43.  
  44. int numTokens = 0;
  45. StringTokenizer st = new StringTokenizer (s1,"+");
  46.  
  47. // bucle por todas las palabras
  48. while (st.hasMoreTokens())
  49. {
  50. s2 = st.nextToken();
  51. Abr.add(s2);
  52. numTokens++;
  53. System.out.println (" Palabra " + numTokens + " es: " + s2);
  54. }
  55.  
  56. }} catch (IOException ex) {
  57. Logger.getLogger(Stream.class.getName()).log(Level.SEVERE, null, ex);
  58. }
  59. System.out.println("ABR "+Abr);
  60.  
  61. }
  62.  
  63. public void search() throws FileNotFoundException{
  64. String DATOS;
  65. for(int x=0;x<Abr.size();x++){
  66. if(Abr.get(x).equals("from")){
  67. System.out.println("Se encontro from "+Abr.get(x)+" en la posicion: "+x);
  68.  
  69. String Table= Abr.get(x+1).toString();
  70. int TmT=Table.length();
  71. String cortado;
  72. cortado = Table.substring(0,TmT-1);
  73. System.out.println("Cortado = "+cortado);
  74. Put_in_memory(cortado);
  75.  
  76. }
  77. }
  78. }
  79.  
  80. //busqueda de Facturas
  81. public void search_F() throws FileNotFoundException{
  82. String DATOS="";
  83. for(int x=0;x<Abr.size();x++){
  84. if(Abr.get(x).equals("Facturas;")){
  85. System.out.println("Se encontro from "+Abr.get(x)+" en la posicion: "+x);
  86. for(int y=0; y<Abr.size();y++)
  87. if(DATOS!="select"){
  88. int t=x-1;
  89. System.out.println("Datos --> "+t);//+DT);
  90. DATOS=Abr.get(t).toString();
  91. DT.add(DATOS);
  92. t--;
  93. }
  94. System.out.println("Datos --> "+DT);
  95.  
  96. }
  97. }
  98. }
  99.  
  100.  
  101. public void search_Data(String data) throws FileNotFoundException{
  102. for(int x=0;x<MTX.size();x++){
  103. if(MTX.get(x).equals(data)){
  104. System.out.println("Se encontro Campos "+MTX.get(x)+" en la posicion: "+x);
  105. int m=3;
  106. String Campos=(String) MTX.get(x+m);
  107. m=m+3;
  108. DAT_to_Print.add(Campos);
  109.  
  110.  
  111.  
  112. // for(int y=0;y<MTX.size();y++){
  113. //
  114. // }
  115.  
  116. //int TmT=Table.length();
  117. //String cortado;
  118. //cortado = Table.substring(0,TmT-1);
  119. //System.out.println("Cortado = "+cortado);
  120. //Put_in_memory(cortado);
  121. }
  122. }
  123. System.out.println("Dat_to_Print = "+DAT_to_Print);
  124. }
  125. public void search_After_Select() throws FileNotFoundException{
  126. // Cargamos el buffer con el contenido del archivo
  127. //try{
  128. // BufferedReader br = new BufferedReader (new FileReader ("archivo_prueba.txt"));
  129. //
  130. // // Leemos la primera linea
  131. //
  132. // while((s1 = br.readLine())!=null){
  133. //
  134. //// System.out.println ("La primera linea del archivo es: " + s1);
  135. //// System.out.println ("La linea tiene " + s1.length() + " caracteres");
  136. ////
  137. //// System.out.println ();
  138. //// System.out.println ("Separando la linea en trozos tenemos las siguientes palabras:");
  139. //
  140. // int numTokens = 0;
  141. // int numTokens2 = 0;
  142. // StringTokenizer st = new StringTokenizer (s1,"+,");
  143. //
  144. // // bucle por todas las palabras
  145. // while (st.hasMoreTokens())
  146. // {
  147. // ss2 = st.nextToken();
  148. // Abr2.add(ss2);
  149. // }
  150. //
  151. // for(int a=0;a<Abr2.size();a++)
  152. // for(int f=0;f<MTX.size();f++)
  153. // for(int c=0;c<CL.size();c++)
  154. // if(Abr2.get(a).equals("*")){
  155. // // System.out.println("ASterisco");
  156. // System.out.println (" Asterisco " +" es: " +Abr2.get(a));
  157. // }
  158. // else if(Abr2.get(a).equals(MTX.get(f))){
  159. // switch(id){
  160. // case 0:
  161. // System.out.println("ERROR EN CAMPOS Y/O TABLA factura");
  162. // case 1:
  163. // //System.out.println("Datos...FAC----");
  164. // System.out.println (" Fac es: " + MTX.get(f));
  165. //
  166. // }
  167. // }else if(Abr2.get(a).equals(CL.get(c))){
  168. // switch(id){
  169. // case 0:
  170. // System.out.println("ERROR EN CAMPOS Y/O TABLA clientes");
  171. // case 1:
  172. // //System.out.println("Datos...FAC----");
  173. // System.out.println (" Clientes es: " + CL.get(f));
  174. //
  175. // }
  176. // }
  177. // }
  178. //
  179. // } catch (IOException ex) {
  180. // Logger.getLogger(Stream.class.getName()).log(Level.SEVERE, null, ex);
  181. //
  182. // System.out.println("ABR2 "+Abr2);
  183. // }
  184. }
  185.  
  186. public void Put_in_memory(String name) throws FileNotFoundException{
  187. String nom=name+".txt";
  188. File n=new File(nom);
  189.  
  190. if(!n.exists()){
  191. System.out.println("Error Tabla "+name +" no Existe!!!");
  192. }
  193. else{
  194. if(name.equals("Facturas")) {
  195. try {
  196. BufferedReader brs = new BufferedReader (new FileReader ("Facturas.txt"));
  197.  
  198. // Leemos la primera linea
  199.  
  200. while((s = brs.readLine())!=null){
  201. // int numTokens = 0;
  202. StringTokenizer st = new StringTokenizer (s,"+");
  203.  
  204. // bucle por todas las palabras
  205. while (st.hasMoreTokens())
  206. {
  207. SS = st.nextToken();
  208. MTX.add(SS);
  209.  
  210.  
  211. }
  212. id=1;
  213. }
  214. System.out.println("MTX "+MTX);
  215. try{
  216. BufferedReader br = new BufferedReader (new FileReader ("archivo_prueba.txt"));
  217.  
  218. // Leemos la primera linea
  219.  
  220. while((s1 = br.readLine())!=null){
  221.  
  222. // System.out.println ("La primera linea del archivo es: " + s1);
  223. // System.out.println ("La linea tiene " + s1.length() + " caracteres");
  224. //
  225. // System.out.println ();
  226. // System.out.println ("Separando la linea en trozos tenemos las siguientes palabras:");
  227.  
  228. int numTokens = 0;
  229. int numTokens2 = 0;
  230. StringTokenizer st = new StringTokenizer (s1,"+,");
  231.  
  232. // bucle por todas las palabras
  233. while (st.hasMoreTokens())
  234. {
  235. ss2 = st.nextToken();
  236. Abr2.add(ss2);
  237. }
  238. }
  239.  
  240. for(int a=0;a<DT.size();a++)
  241. for(int f=0;f<3;f++)
  242. // for(int c=0;c<CL.size();c++)
  243. switch(id){
  244. case 0:
  245. System.out.println("Error en Tabla y/o Campos no existentes");
  246. case 1:
  247. if(DT.get(a).equals("*")){
  248. System.out.println("Asterisco--> "+DT.get(a));
  249. }else if(DT.get(a).equals(MTX.get(f))){
  250. System.out.println("Campo Facts--> "+MTX.get(f));
  251. }
  252. }
  253.  
  254. } catch (IOException ex) {
  255. Logger.getLogger(Stream.class.getName()).log(Level.SEVERE, null, ex);
  256.  
  257. System.out.println("ABR2 "+Abr2);
  258. }
  259. }
  260.  
  261. catch (IOException ex) {
  262. Logger.getLogger(Obtiene_Matriz_de_Archivo.class.getName()).log(Level.SEVERE, null, ex);
  263. }
  264. }else
  265. {System.out.println("Error en Tabla no existente");
  266. id=0;
  267. }
  268. if(name.equals("Clientes")) {
  269. try {
  270. BufferedReader brs = new BufferedReader (new FileReader ("Clientes.txt"));
  271.  
  272. // Leemos la primera linea
  273.  
  274. while((c = brs.readLine())!=null){
  275. // int numTokens = 0;
  276. StringTokenizer cl = new StringTokenizer (c,"+");
  277.  
  278. // bucle por todas las palabras
  279. while (cl.hasMoreTokens())
  280. {
  281. CC = cl.nextToken();
  282. CL.add(CC);
  283. id=1;
  284.  
  285. }
  286. }
  287. System.out.println("clientes "+CL);
  288. }
  289.  
  290. catch (IOException ex) {
  291. Logger.getLogger(Obtiene_Matriz_de_Archivo.class.getName()).log(Level.SEVERE, null, ex);
  292. }
  293. }else
  294. {System.out.println("Error en Tabla no existente");
  295. id=0;
  296. }
  297.  
  298. // MTX.clear();
  299. // System.out.println("MTX "+MTX);
  300. }
  301. }
  302. public static void main (String[] args) throws FileNotFoundException
  303. {
  304. SQL OBM = new SQL();
  305. OBM.AN_SQL();
  306. OBM.search();
  307. OBM.search_F();
  308. OBM.search_After_Select();
  309.  
  310. }
  311.  
  312. }

problem
 
.
X

Se parte de Code Army!

Esta acción es solo para usuarios registrados