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

  • SEARCH
  • Home
  • 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 8332805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:49:36+00:00 2026-06-09T02:49:36+00:00

public static Connection connect; public static ResultSet resultSet; static final String DATABASE_URL = jdbc:mysql://localhost/java_dev;

  • 0
public static Connection connect;
    public static ResultSet resultSet;
    static final String DATABASE_URL = "jdbc:mysql://localhost/java_dev";

    public ServerFunctions() {
        String Driver = "com.mysql.jdbc.Driver";            
        String DB_USERNAME = "lucky";
        String DB_PASSWORD = "lucky";

        try {
            Class.forName(Driver);
            connect = DriverManager.getConnection(DATABASE_URL,DB_USERNAME, DB_PASSWORD);
        } catch(Exception e) {
            System.out.println("Database Not Connected ! ");
        }
    }

    public static Boolean verificator(String username, String password) {
        try {
            PreparedStatement prepare = connect.prepareStatement(
                "Select * from users where username='?'&&password='?'");

Above is my code fragment. I am declaring the Connection and Resultset objects static so they can be called from the static verificator method.
also the verificator method is declared static so that it can be called from a different class as class variable just by using className.verificator(param, param).

It compiles and run when I test the class alone but then i get the NullPointerException error at the PerparedStatement Line whenever a call is made from different class.

Can someone Please help me why it is Happening ?

Thankyou

  • 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-06-09T02:49:37+00:00Added an answer on June 9, 2026 at 2:49 am

    You said you declared the verificator method as static, so it can be accessed from other classes, and the verificator method is using the connection, which is also static.

    The problem is that the connection is only initialized in the constructor of the object, so, if the constructor is never called, connect will be null.

    You need to either initilize your connect variable in a static block, or verify if it is null before using it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public class Db_try1 { public static void main(String[] args) { String driver=oracle.jdbc.OracleDriver; String url=jdbc:oracle:thin:@localhost:1521:xe;
I have the following method: public static T ExecuteScalar<T>( string query, SqlConnection connection, params
I have the following code to connect to a mysql db : public static
Possible Duplicate: ClassNotFoundException com.mysql.jdbc.Driver I have included the mysql-connector-java-5.1.16-bin.jar into my Eclipse library, this
public class FtpDownloadDemo { public static void Connection(String filename) { FTPClient client = new
Okay, so i have this code i wrote: class Connection { public static StreamWriter
public static class TestTask extends AsyncTask<Void, Integer, Integer> { private String stacktrace; public TestTask
public static void main(String[] args) { int i = 0; while(i==0){ System.out.println(Possibilities: R, T,
public static void main(String[] args) { // TODO Auto-generated method stub BufferedReader br1 =
public static void main(String Data[]) { ConnectionPoolDataSource dps; try { cnt=new InitialContext(); cnt.rebind(java:comp/env/jdbc/pool/dragon, dps);

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.