Java Querying SQL Help/Questions
Go to solution
Solved by RaidenLeeChin,
Try:
public void Querrying(){try { Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/linuslinus", "notaniel101", "aaaaa"); Statement st = con.createStatement(); ResultSet result = st.executeQuery("SELECT * FROM inventory WHERE id = '" + product + "'"); if (!result.isBeforeFirst()) {System.out.println("SORRY THAT PRODUCT ID DOES NOT EXIST");}else{ while (result.next()) { System.out.println(result.getInt("id")); System.out.println(result.getInt("quantity")); System.out.println(result.getString("type")); System.out.println(result.getString("size")); System.out.println(result.getString("style")); ObTYPE = result.getString("type"); ObSIZE = result.getString("size"); ObSTYLE = result.getString("style"); ObQUANTITY = result.getInt("quantity"); NTQUANTITY = ObQUANTITY; EndingQUANTITY.setText("New Total Quantity ="+ObQUANTITY); SIZE.setText("Size = "+ObSIZE); STYLE.setText("Style = "+ObSTYLE); GENDER.setText("Gender = "+ObTYPE); } } result.close(); con.close(); }catch (ClassNotFoundException e) { System.out.println("Driver not found");} catch (SQLException e) { e.printStackTrace(); System.out.println("following error occured "+e);} }
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now