• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 218
  • Last Modified:

Problems adding variables to a table

Hi Experts,

Hope some1 can help me. I need to add some variables to a table, but keep getting SQLError: can not issue data manipulation statements with executeQuery()

The Guest are allowed to manipulate data though

Anyway, here's the code for it:

      public void insertFileToDB(String theFile, String theFolder)
      {
            System.out.println("at database: " + theFile +" : "+ theFolder);
            String userName = "guest";
            String password = "guest";
            String url = ("jdbc:mysql://172.18.4.61/IdarNet");
            try
            {            
                  Class.forName("com.mysql.jdbc.Driver").newInstance();                  
                  conn = DriverManager.getConnection (url, userName, password);                  
                  String strSQL = "INSERT INTO filelist (addresses, file, folder) VALUES ('172.18.5.192', '"+theFile+"', '"+theFolder+"');"; // Put your SQL query here      
                  Statement stmt = conn.createStatement();                  
                  ResultSet result; //temp                        
                  result = stmt.executeQuery(strSQL); // STORE DaTA
                  result.close();
            }
            catch (Exception e )
            {
                  System.out.println(e);
                  e.printStackTrace();
            }
            finally
            {
                  if(conn != null)
                  {
                        try
                        {
                              conn.close();
                              System.out.println("Client: Database connection terminated2");
                        }
                        catch(Exception e)
                        {/*ignore*/}
                  }
            }      
      }
}
0
Idarhillgaar
Asked:
Idarhillgaar
  • 4
  • 2
1 Solution
 
CEHJCommented:
You need to call executeUpdate
0
 
CEHJCommented:
int resultOfQuery = stmt.executeUpdate(strSQL);
0
 
IdarhillgaarAuthor Commented:
hey that was quick, and it worked.

However when I store ie. c:\temp\01.temp in a variable I cant store it as c:\\temp\\01.temp as would be correct in the database. anyway around this??
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
CEHJCommented:
Not quite sure what you mean in your question here, but think

String s =  "c:\\\\temp\\\\01.temp";

should do it
0
 
IdarhillgaarAuthor Commented:
I'm reading the filenames in dynamically to a hashtable and these are then being stored to the database by displaying hashtable at runtime. Doesn't seem to be a natural way when I need to store c:\temp\01.temp as c:\\temp\\01.temp

read filename and fileadress to hashtable

               File[] files = from.listFiles();
               for (int i = 0; i < files.length; i++)
               {
                    listFiles(files[i]);
               }
               return;
          }
         
          files.put(from.getName(), from.getAbsolutePath());

Hashtable Read and passing both filename and fileaddress
like this:
    public void showHash()
    {
          Enumeration e = files.keys();
          
          while(e.hasMoreElements())
          {
                String fileName = (String) e.nextElement();
                String folderAddress = files.get(fileName).toString();
                InsertFileList insert = new InsertFileList();
                insert.insertFileToDB(fileName, folderAddress);
0
 
CEHJCommented:
String path = someFile.getAbsolutePath().replaceAll("\\\\", "\\\\\\\\");
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now