package sample; import java.sql.*; import net.sf.json.JSONArray; import net.sf.json.JSONObject; public class test { Connection conn; Statement st ; ResultSet rs; public void getconn() { try { String connectionURL= ("jdbc:mysql://localhost:3306/demodata"); Class.forName("com.mysql.jdbc.Driver"); conn = DriverManager.getConnection(connectionURL, "root", "yashu"); if(!conn.isClosed()) { System.out.println("Successfully connected ..."); } } catch(Exception ex){ System.out.println("Unable to connect to database."); } } public void getsel() { try{ java.sql.ResultSetMetaData rsmd = rs.getMetaData(); conn.createStatement(); rs=st.executeQuery("select * from emp where empid=1"); //Integer i1=Integer.parseInt(rs.getString(1)); JSONArray arrayObj=new JSONArray(); while(rs.next()){ int numColumns = rsmd.getColumnCount(); JSONObject obj = new JSONObject(); for (int i=1; i<numColumns+1; i++) { String column_name = rs.getColumnName(i); if(rsmd.getColumnType(i)==java.sql.Types.ARRAY){ obj.put(column_name, rs.getArray(column_name)); } else if(rsmd.getColumnType(i)==java.sql.Types.BIGINT){ obj.put(column_name, rs.getInt(column_name)); } else if(rsmd.getColumnType(i)==java.sql.Types.BOOLEAN){ obj.put(column_name, rs.getBoolean(column_name)); } else if(rsmd.getColumnType(i)==java.sql.Types.BLOB){ obj.put(column_name, rs.getBlob(column_name)); } else if(rsmd.getColumnType(i)==java.sql.Types.DOUBLE){ obj.put(column_name, rs.getDouble(column_name)); } else if(rsmd.getColumnType(i)==java.sql.Types.FLOAT){ obj.put(column_name, rs.getFloat(column_name)); } else if(rsmd.getColumnType(i)==java.sql.Types.INTEGER){ obj.put(column_name, rs.getInt(column_name)); } else if(rsmd.getColumnType(i)==java.sql.Types.NVARCHAR){ obj.put(column_name, rs.getNString(column_name)); } else if(rsmd.getColumnType(i)==java.sql.Types.VARCHAR){ obj.put(column_name, rs.getString(column_name)); } else if(rsmd.getColumnType(i)==java.sql.Types.TINYINT){ obj.put(column_name, rs.getInt(column_name)); } else if(rsmd.getColumnType(i)==java.sql.Types.SMALLINT){ obj.put(column_name, rs.getInt(column_name)); } else if(rsmd.getColumnType(i)==java.sql.Types.DATE){ obj.put(column_name, rs.getDate(column_name)); } else if(rsmd.getColumnType(i)==java.sql.Types.TIMESTAMP){ obj.put(column_name, rs.getTimestamp(column_name)); } else{ obj.put(column_name, rs.getObject(column_name)); } }//end foreach json.put(obj); }//end while } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return json; } public void getupt() { } }
Post your Comment
Replace an object with set(int, Object) method Replace an object with set(int, Object) method  ... that provides the usage of the set(int, object) method in more detail. Create... objects using the add(int,object) method. Now replace an object from a particular
conver object to int conver object to int i have a method returns object but i need int how can convert ? notice:object not means string means object string str map.get(str) returns object but i need an integer
Convert Object to Int Convert Object to Int  ... Object into a primitive type int and Integer Object to primitive type int. . ... into primitive type int and Integer type object to primitive type int. The parseInt
Object reference not set to an instance of an object Object reference not set to an instance of an object Object reference not set to an instance of an object
Insert an element with the add(int, Object) method Insert an element with the add(int, Object) method  ... an element at the specified position using the add(int, Object) method. Here is an example that provides the usage of the add(int, Object) method in more detail
object and method object and method a college would like to automate managing courses offered to students. initially only three courses are involved. each courses has... and an application that creates the necessary object
getAttribute() Method Of The Request Object that is set through the setAttribute() method of the request object. The getAttribute... getAttribute() Method Of The Request Object... for the illustration of the getAttribute() method of the request object in JSP
Prepared Statement Set Object : prepareStatement(String sql): This method returns the PreparedStatement object for sending... by using the given object in this method. It takes two arguments to given... Prepared Statement Set Object  
setAttribute() Method Of The Request Object the request object through the dispatcher method. The set value of the attribute... setAttribute() Method Of The Request Object... the best illustration about the setAttribute() method of the request object in JSP
PHP set static Method return the object. PHP Set Static Method Example: <?php class A { public..._set_static()Method in PHP : In this tutorial we will study how to assign values of an object to another object dynamically. To do this we use __set_static
Method is undefined for the type Object(org.apache.jasper.JasperException) Method is undefined for the type Object(org.apache.jasper.JasperException) ... = ""; for (int i = 0; i <.../bap/editPracticeRevenuSplit.jsp Generated servlet error: The method
JSP implicit object "response" parameters can be modified or set. The response object handles...) setContentType(): The "setContentType()" method of response object is used...;containsHeader()" method of response object is used to check whether the header
Creating JDBC Statement object object. This result set object contains the result of the query. Statement interface provides basic method for SELECT, INSERT, UPDATE, DELETE operations...; } Creating JDBC Statement Object JDBC Statement is an interface of java.sql.
Null value when i set interface object in form controller - Spring Null value when i set interface object in form controller Hi all, i am very new about spring and hibernate. i got null value when i set interface object in form Controller. public void setOHBillManager(OHBillManager
Insert an object with the add(Object) method Insert an object with the add(Object) method  ... at the end of a list using the add(Object) method. Here is an example that provides the usage of the add(Object) method in more detail. Create a class "
Method ; In this section, we will explore the concept of method in the reference of object oriented... of method in java object-oriented technique first one is the Instance method...; Method Overriding Overriding is another useful feature of object
Object Oriented Programming II Object Oriented Programming II Instructions: ->each class... -"length" of type int -"width" of type int -"content" of type String provide a method to compute the area of the paper Create a class named "Envelope
getQueryString() Method Of The Request Object getQueryString() Method Of The Request Object... the getQueryString() method of the request object. Here, you will learn more...;title>getQueryString() method of request object.</title></head> <
Java using Netbeans Object Oriented Programming Java using Netbeans Object Oriented Programming I am trying to make a program that uses a main class and a separate class with one public method and one private method. The main method in the main class asks the user for 2
removeAttribute() Method Of The Request Object removeAttribute() Method Of The Request Object... for the method removeAttribute() of the request object. This method removes... the removeAttribute() method of the request object in JSP by learning through
Object does not support proprty or method Object does not support proprty or method Hi I have been given some... on a network machine it returns a error which say's Object does'nt support this property or method. It seems to have a problem with this type of line
Object Object An object...). In an object, variables store values for later use and methods are the unit... are the basic units of the object-oriented programming. Objects are the part of our day
Object Adapter based on Dynamic Proxy,java,Dynamic Object Adapter using Dynamic Proxies,newsletter,tutorial invoke(Object proxy, Method method, Object[] args... Object Adapter based on Dynamic Proxy 2005-05-10 The Java Specialists' Newsletter [Issue 108] - Object Adapter based on Dynamic Proxy
object object is it possible to create object in the same class..?. Yes, you can. class CreateObject { CreateObject(){ System.out.println("I have an object."); } public static void main(String[] args
PDO Fetch Object PDO Fetch Object: This is another way to access the data of a table, accessing fields as object. By using this method we get the result set as anonymous object and this object represents the field names of the table as object
getParameterValues() Method Of The Request Object getParameterValues() Method Of The Request Object... about the getParameterValues() method of the request object. Here, you will learn... of the getParameterValues() method of the request object: String[] parameterValues
getParameter() method of request object.
getParameterNames() Method Of The Request Object getParameterNames() Method Of The Request Object... the detailed explanation about the getParameterNames() method of the request object. You... of the request object. Why the method used and how to use? All the things about
object as argument object as argument what happens when we pass a object into a method???if java is pass by value how does this makes a difference.....pllzzz give me more clarification on why we pass objects in a margument
getHeader() Method Of The Request Object getHeader() Method Of The Request Object  ... illustration about the getHeader() method of the request object. Here, you will learn... retrieved by the method getHeaderNames() of the request object that gives all
javasimha November 7, 2011 at 2:08 PM
package sample; import java.sql.*; import net.sf.json.JSONArray; import net.sf.json.JSONObject; public class test { Connection conn; Statement st ; ResultSet rs; public void getconn() { try { String connectionURL= ("jdbc:mysql://localhost:3306/demodata"); Class.forName("com.mysql.jdbc.Driver"); conn = DriverManager.getConnection(connectionURL, "root", "yashu"); if(!conn.isClosed()) { System.out.println("Successfully connected ..."); } } catch(Exception ex){ System.out.println("Unable to connect to database."); } } public void getsel() { try{ java.sql.ResultSetMetaData rsmd = rs.getMetaData(); conn.createStatement(); rs=st.executeQuery("select * from emp where empid=1"); //Integer i1=Integer.parseInt(rs.getString(1)); JSONArray arrayObj=new JSONArray(); while(rs.next()){ int numColumns = rsmd.getColumnCount(); JSONObject obj = new JSONObject(); for (int i=1; i<numColumns+1; i++) { String column_name = rs.getColumnName(i); if(rsmd.getColumnType(i)==java.sql.Types.ARRAY){ obj.put(column_name, rs.getArray(column_name)); } else if(rsmd.getColumnType(i)==java.sql.Types.BIGINT){ obj.put(column_name, rs.getInt(column_name)); } else if(rsmd.getColumnType(i)==java.sql.Types.BOOLEAN){ obj.put(column_name, rs.getBoolean(column_name)); } else if(rsmd.getColumnType(i)==java.sql.Types.BLOB){ obj.put(column_name, rs.getBlob(column_name)); } else if(rsmd.getColumnType(i)==java.sql.Types.DOUBLE){ obj.put(column_name, rs.getDouble(column_name)); } else if(rsmd.getColumnType(i)==java.sql.Types.FLOAT){ obj.put(column_name, rs.getFloat(column_name)); } else if(rsmd.getColumnType(i)==java.sql.Types.INTEGER){ obj.put(column_name, rs.getInt(column_name)); } else if(rsmd.getColumnType(i)==java.sql.Types.NVARCHAR){ obj.put(column_name, rs.getNString(column_name)); } else if(rsmd.getColumnType(i)==java.sql.Types.VARCHAR){ obj.put(column_name, rs.getString(column_name)); } else if(rsmd.getColumnType(i)==java.sql.Types.TINYINT){ obj.put(column_name, rs.getInt(column_name)); } else if(rsmd.getColumnType(i)==java.sql.Types.SMALLINT){ obj.put(column_name, rs.getInt(column_name)); } else if(rsmd.getColumnType(i)==java.sql.Types.DATE){ obj.put(column_name, rs.getDate(column_name)); } else if(rsmd.getColumnType(i)==java.sql.Types.TIMESTAMP){ obj.put(column_name, rs.getTimestamp(column_name)); } else{ obj.put(column_name, rs.getObject(column_name)); } }//end foreach json.put(obj); }//end while } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return json; } public void getupt() { } }
Post your Comment