java Multi query from Mysql using netbeans -



java Multi query from Mysql using netbeans -

i have java code retrieve info mysql appropriate code in netbeans.the code below. want multi query such illustration finding total number of products , on.could help me please. in advance

import java.sql.*; public class javamysqlselectexample { public static void main(string[] args) { seek { string mydriver = "com.mysql.jdbc.driver"; string myurl = "jdbc:mysql://localhost/sample"; class.forname(mydriver); connection conn = drivermanager.getconnection(myurl, "root", "mypasscode1"); string query = "select * products"; statement st = conn.createstatement(); resultset rs = st.executequery(query); while (rs.next()==true) { int code = rs.getint("code"); string productname = rs.getstring("product_name"); string producttype = rs.getstring("product_type"); system.out.format(" %d, %s, %s\n", code, productname, producttype); } st.close(); } grab (exception e) { system.err.println("error message: "); system.err.println(e.getmessage()); }

} }

create statement query again. don't close connection database until finish job. until user disconnects, db connection can alive.(best case)

database connection consuming job code if open connection each request, cause bad performance.

select count(1) products : gives total number of products

or

long counter = 0; while (rs.next()==true) { int code = rs.getint("code"); counter++; string productname = rs.getstring("product_name"); string producttype = rs.getstring("product_type"); system.out.format(" %d, %s, %s\n", code, productname, producttype); } system.out.println("total product count : " + counter);

java netbeans mysqli-multi-query

Comments

Popular posts from this blog

c# - DotNetZip fails with "stream does not support seek operations" -

c++ - StartServiceCtrlDispatcher don't can access 1063 error -