Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7594403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:24:26+00:00 2026-05-30T21:24:26+00:00

Need help with below code. I am trying to query from same table and

  • 0

Need help with below code.

I am trying to query from same table and update a record.

import java.sql.* ;

class Connect
{
 public static void main( String args[] )
 {
  try
  {
      // Load the database driver
      Class.forName( "com.microsoft.sqlserver.jdbc.SQLServerDriver" ) ;

      // Get a connection to the database
      Connection conn = DriverManager.getConnection( "jdbc:sqlserver://localhost:1433;user=sa;password=root;databaseName=blueprint") ;

      // Print all warnings
      for( SQLWarning warn = conn.getWarnings(); warn != null; warn = warn.getNextWarning() )
      {
          System.out.println( "SQL Warning:" ) ;
          System.out.println( "State  : " + warn.getSQLState()  ) ;
          System.out.println( "Message: " + warn.getMessage()   ) ;
          System.out.println( "Error  : " + warn.getErrorCode() ) ;
      }

      // Prepare a statement
      String sql = "select DN, WD from table1 ";

      Statement cs = conn.createStatement();
      // Execute the query
      ResultSet rs = cs.executeQuery(sql) ;


      // Loop through the result set
      int i = 0;
      while( rs.next() ) 

         System.out.println( rs.getString("DN") + " " + rs.getString("WD") ) ;
         String dm = rs.getString("DN");  
         String wi = rs.getString("WD");
         iupdateQuery(i, dm, wi);
         i++;


      // Close the result set, statement and the connection
      rs.close() ;
      cs.close() ;
      conn.close() ;

  }
  catch( SQLException se )
  {
      System.out.println( "SQL Exception:" ) ;

      // Loop through the SQL Exceptions
      while( se != null )
      {
          System.out.println( "State  : " + se.getSQLState()  ) ;
          System.out.println( "Message: " + se.getMessage()   ) ;
          System.out.println( "Error  : " + se.getErrorCode() ) ;

          se = se.getNextException() ;
      }
  }
  catch( Exception e )
  {
      System.out.println( e ) ;
  }
 }

 private void iupdateQuery(int i, String dm, String wi) {

                String sdm = dm;
                String swi = within;

                String query = "UPDATE table1 SET WDIO ='" + swi
                                + "' WHERE (DN ='" + sdm + "');";

                // debug
                System.out.println(i + ". " + query);

                try {

                        Statement update = conn.createStatement();
                        update.executeUpdate(query);

                } catch (Exception e) {
                        // debug out output this way
                        System.err.println("Mysql Statement Error: " + query);
                        e.printStackTrace();
                }
        }

}

Getting below error if i execute.

C:\test>javac Connect.java
Connect.java:48: non-static method iupdateQuery(int,java.lang.String,java.lang
tring) cannot be referenced from a static context
         iupdateQuery(i, dm, within);
         ^
Connect.java:91: cannot find symbol
symbol  : variable conn
location: class Connect
                        Statement update = conn.createStatement();
                                           ^
2 errors

Please let me know if i am doing any thing wrong.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T21:24:28+00:00Added an answer on May 30, 2026 at 9:24 pm

    Make the method static, like this:

    private static void iupdateQuery(int i, String dm, String wi) {
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some help with the code below. What I'm trying to do is
i need help with disk_total_space function.. i have this on my code <?php $sql=select
I need help, I am trying to make use of Lattice Multiplication in java
I need help in understanding the code snipped below...allocate is a function that would
I have this code UPDATE OPENQUERY (db,'SELECT * FROM table WHERE ref = ''+
The coding below seperates the $state data, I need help putting the var_dump info
Need help writing a script downloads data from google insight using c# this is
I need help on this following aspx code aspx Code: <asp:Label ID =lblName runat
I need help understanding some C++ operator overload statements. The class is declared like
I need some help in fixing the below issue. I had transaction blocks in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.