I am attempting to create a database connection and update using a prepared statement with JDBC to MYSQL.  I have tried changing the connection a bit and had to change the preparedStatement class to static in order to not get errors.  However, when running the app I got a NullPointerException error and I can't see where exactly I need to create a new object.  Currently, I get an error:     Exception in thread "main" java.lang.NullPointerException           at Alter.main(Alter.java:12)      import java.sql.PreparedStatement; import java.sql.SQLException;  public abstract class Alter {      public static void main(String[] args) throws SQLException {                   String query = "INSERT INTO school.students (First_Name, Last_Name, Gender, Grade_Level, IEP, Disruptive_1to5_LowtoHigh, OffTask_1to5_LowtoHigh, Not_Responsible_1to5_LowtoHigh, Not_GetAlong_1to5_LowtoHigh) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";                  PreparedStatement myStmt = Connection.prepareStatement(query);                           myStmt.setString(1, "Chris");                     myStmt.setString(2, "Johnson");                     myStmt.setString(3, "Male");                     myStmt.setString(4, "K");                     myStmt.setString(5, "N");                            myStmt.setInt(6, 1);                     myStmt.setInt(7, 3);                     myStmt.setInt(8, 5);                     myStmt.setInt(9, 2);                     myStmt.addBatch();                      int[] result = myStmt.executeBatch();                      System.out.println(result + " were added to the database.");      } }   import java.sql.*;  public class Connection extends Alter {     {     try {          Class.forName("com.mysql.cj.jdbc.Driver").getDeclaredConstructor().newInstance();      }          catch (Exception ex) {          }     try {          batchInsertRecordsIntoTable();      } catch (SQLException e) {          System.out.println(e.getMessage());      } }      final static void batchInsertRecordsIntoTable() throws SQLException {         {             try {           DriverManager.getConnection(                      "jdbc:mysql://localhost:3306/school?allowPublicKeyRetrieval=true&amp;useSSL=false&amp;serverTimezone=UTC",                        "root", "");           System.out.println("Connection Successful"); }       catch (SQLException ex) {          ex.printStackTrace();      }         } }      public Statement createStatement() {         return null;     }      public static PreparedStatement prepareStatement(String query) {         return null;     } }
What are Null Pointer Exceptions (java.lang.NullPointerException) and what causes them?  What methods/tools can be used to determine the cause so that you stop the exception from causing the program to terminate prematurely?
Get the last item in an array I've got a PDF that is automatically generated from a certain piece of software, that I want to include in the report I'm writing. I'm using pdfpages which gets the job done elegantly, but the problem is, the PDF has a lot of white space around the actual content (which is a graphics) and I always have to do some tedious post-processing of the automatically generated document so that it fits well in my report. Changing the output of the software to eliminate the white space is not an option (or at least, would be much more trouble than it's worth).  I checked the pdfpages , but wasn't able to find an option that does that. Ideally, I'd like to be able to set margins from each direction, and the PDF is then cropped accordingly and included.  What other options do I have to control what portion of the included PDF is visible in the final document? Edits on closed posts Should questions or answers on questions that are closed be edited, even if the question is closed and the edit does not change anything about the reason it's closed? Example:  was just edited, which I saw in the review queue. It certainly improves the answer, but since the answer doesn't really have to exist on SE at all (because the question is off-topic), should this edit be made? In my understanding, the only reason that the edit option for a closed question is not greyed out is so that it can be edited to make it comply with the SE rules. "Whether" Vs. "If" What is the regular expression for a decimal with a precision of 2?  Valid examples:  123.12 2 56754 92929292929292.12 0.21 3.1   Invalid examples:  12.1232 2.23332 e666.76   The decimal point may be optional, and integers may also be included. What is the difference between == and === in php. I am unsure when to use both.  Updated note: So that it shows up in StackOverflow search, the difference between == and === is the same as the difference between != and !==. What is this mark over the question When I open a site I see a mark over a question.See screen shot.  When I open the question mark is not remove.It still appear.    is this bug or? Simple examples of uncorrelated but not independent $X$ and $Y$ Do objects rotate around the torque vector or its center? If a sphere has a torque vector coming out of it at point A, would the sphere rotate about its center or the axis of the torque vector? Given a pointed category $X$, is $|N(X)|$ contractible ($N(X)$ is the nerve of $X$)? Or are there counter-examples? How to use host names rather than ip addresses on home network? I've a small home network up and running and managed to set up ssh. Can anyone tell me what I need to do to refer to one computer on the network from another by host name rather than IP address (which is what I'm doing now)? What does each AMS package do? In my view, any document with a substantial amount of mathematics should load the packages from AMS-TeX. Hence, most of my document's preambles contain  \usepackage{amsmath, amsthm, amssymb, amsfonts}   (I could add to that the non-AMS mathtools, etc.). What do each of those packages do? Do I really need to list all of them, or do some of them load others? In particular, does any package load all of them, so that I can simply type  \usepackage{ams-everything}   shorter than the current list? Cannot connect MacBook Pro (Retina, 15-inch, Mid 2015) (10.13.3) to the internet through my Apple USB Ethernet Adapter. I am receiving this error under System Preferences/Network:   "Apple USB Ethernet Adapter has a self-assigned IP address and will not be able to connect to the Internet." IP Address: 169.254.59.248 Subnet Mask: 255.255.0.0   I can connect to the internet with the same ethernet port on my Windows 10 machine. When I replace the IP address with a the Wi-Fi IP address I use to successfully connect to the same network under "Using DHCP with manual address", the Apple USB Ethernet Adapter icon is green and displays the message "Apple USB Ethernet Adapter is currently active and has the IP address xx.xx.xx.252." However there is no actual internet connection (i.e., I cannot visit any website).  According to  to a similar problem, I can:   Find and disable whatever firewall is intercepting the DHCP return traffic. According to System Preferences/Security &amp; Privacy/Firewall, my firewall is off. Is there anywhere else I can check for additional firewalls? Would firewalls somehow impact ethernet and Wi-fi differently?  Inspect the network traffic or the router logs to see if and why the Mac DHCP broadcast packet is being ignored. How do I check network traffic on my Mac? I am comfortable using the terminal.   I have also tried steps listed as potential solutions in :   To reset the firewall, go to the /Macintosh HD/Library/Preferences/ folder and remove the file called "com.apple.alf.plist," and then restart your computer. On my computer I went to /Library/Preferences/ and ran sudo rm com.apple.alf.plist If that was already set, try the "Advanced" button, then "Renew DHCP Lease" Removing their "Ethernet" config from the Network settings and then re-adding   Does anyone have other suggestions? Thanks in advance How to add PlotLegends in a Show function? Show that a ring is commutative if it has the property that ab = ca implies b = c when $a\neq 0$.   This is my proof to show that a ring is commutative if it has the property that ab = ca implies b = c.  We need to show that if x, y ∈ R then xy = yx. Let a = x, b = yx and c = xy. Then ab = x(yx) = (xy)x = ca. Thus, by the hypothesis, b = c, or xy = yx. Thus, for x, y ∈ R we have xy = yx.   How would I show when $a\neq 0$? How to obtain a confidence interval for a percentile? Values of the limit $\lim\limits_{x\to+\infty}\left(\sqrt{(x+a)(x+b)}-x\right)$ Hi I have a question regarding finding the values of limit for the following question.  Let $a, b \in \mathbb R$. Find the limit $$\lim_{x\to+\infty}\left(\sqrt{(x+a)(x+b)}-x\right)$$ I am trying to encrypt an entire USB drive with Truecrypt 7.1a. But as long as there is a partition it will only encrypt that. This will make it appear like the USB is full instead of completely empty, which isnt what Im aiming for.   I've tried with DISKPART, USB Partition Tool, and the built-in storage manager. When I delete all partitions, Windows still assigns the drive a letter and assumes that it has a partition covering the whole space.  I know that it is possible as I have done it with another USB, but I just don't remember how I did it.  Ideas? "Software Updater" & "Software & Updates" not working I havent used my Ubuntu for quite a long time.  Today, when I booted Ubuntu (14.04 LTS), the software updater and Software &amp; Updates (from Settings) are not working.  The software updater's window will show up for around 1 sec, but it will close automatically. Software &amp; Updates is never shown, no matter how many times I click the icon. Note that neither of them show any error message.  Those 2 features were working perfectly the last time I used Ubuntu. I want to do some system upgrade and update.  For now, I use sudo apt-get update &amp;&amp; sudo apt-get upgrade. This command runs very fast, meaning (I think) my Ubuntu is not updated properly. The update from software updater always has a big size hence the download should be slower.  What should I do?   Can I just uninstall and reinstall both of them? If I can, how to do it?  Just to clarify, I don't want to upgrade my Ubuntu version (I want the LTS one), I just want to upgrade the software/packages I used.  Thanks for your time. Do I need a UK visa? How and where to apply? I live in Germany since May 2013 as a spouse of German citizen. In Nov 2015 we divorced and I have German residence permit till Jan 2018. We have a son in this marriage and legally I have the right to live in Germany indefinitely. I would like to visit my brother and sister who are British citizens living in UK. What is the visa procedure for me to travel to UK for a week.  Do I need a visa to enter UK ?