[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 213
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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