How to use preparedStatement

i want to use a prepare statement to return a recordset...
but i got the following error:
C:\Downloads\java\jasonHunter jservlet2\jservlet2-examples\ch09\DBPhoneLookup5.java:31: incompatible types
found : int
required: java.sql.ResultSet
rs=pstmt.executeUpdate();
^
1 error
Exit code: 1
There were errors
the coding are:
pstmt = con.prepareStatement("SELECT * FROM service where sID=?" , ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
pstmt.setInt(1, Integer.parseInt(ser ));
rs=pstmt.executeUpdate();
rs is RecordSet...
anyone can help??

try executeQuery() or executeQuery(String) with the string
of query and don't use prepareStatement, or you can also add batches with addBatch() and then make executeBatch()..
pick one:)

Similar Messages

  • How to write SDO_GEOMETRY using PreparedStatements ?

    Hi there,
    I use JDBC and JDK 1.3+
    Currently I'm writing geometries into Spatial by using Strings and
    I meet some limitations for very huge geometries.
    That's why I need to use PreparedStatements and parameters to get
    rid of this limitation.
    My question is how can I write Object types by using JDBC. All
    the sample codes I found use oracle.sql and oracle.jdbc packages.
    My problem is that my code can be used by people that may not
    have an Oracle jdbc driver like "thin" for instance.
    thanks for your help,
    ALI

    Justin,
    I have a PL/SQL package that contains several functions. One of them does selection and filtering of spatial features based on a user's location and preferences. For this purpose a web-application runs this function.
    I would like this function to do the following:
    1. the function is called, user parameters are passed in
    2. a call to a java-stored-procedure is made. This java procedure creates a polygon based on the user's location and preferences.
    3. the polygon is returned to the PL/SQL function
    4. the funtion uses the returned polygon to query spatial features that intersect, etc.
    I can do the call to the java-stored-procedure but where I get stuck is how to get the polygon from java to pl/sql. I can return a String or a number from java but how can I return the polygon (e.g., STRUCT, java object)?
    The current solution uses a work-around by storing the polygon in a temporary table. I would like to change this because once the function has run, the polygon is not needed anymore so I would like to do without having to store the polygon.
    Markus

  • How to insert the system date  using PreparedStatement

    How do I insert system date(from Orcale database) using
    PreparedStatement. I am aware that that oracle has date
    function 'sysdate' to retrieve the database current date.
    How Do i use that in the following syntax?
    Alertnative 1:
    String inssql =
    "insert into emp (empid, name, dept, updateDate) "+
    " values (?, ?, ?, ?)";
    PreparedStatement pstmt = conn.prepareStatement(inssql);
    pstmt.setInt(1, 123456);
    pstmt.setString(2, "Bougnon Kipre");
    pstmt.setString(3, "Rare Species Depatement" );
    pstmt.setDate(4, sysdate) // if this okay
    pstmt.executeUpdate();
    Alternative 2:
    String inssql =
    "insert into emp (empid, name, dept, updateDate) "+
    " values (?, ?, ?, sysdate)";
    PreparedStatement pstmt = conn.prepareStatement(inssql);
    pstmt.setInt(1, 123456);
    pstmt.setString(2, "Bougnon Kipre");
    pstmt.setString(3, "Rare Species Depatement" );
    pstmt.executeUpdate();

    Hi,
    The second alternative will be the best way.
    Since the alternative 1 won't work. sysdate cannot be accessed
    from java as a variable. Either use alternative two or create a
    java.sql.Date and insert it.
    Regards
    Elango

  • How to use LIKE operator with PreparedStatement

    Hi, I need to execute a query with the LIKE operator, but using a PreparedStatement. Can I do this, and if so what must my SQL look like with the wildcard characters '%' or '_'?
    normal PS example: conn.prepareStatement("select * from mytable where name like ?");
    If I try: conn.prepareStatement("select * from mytable where name like ?%");
    I get: ORA-00911: invalid character
    If I try: conn.prepareStatement("select * from mytable where name like '?%'");
    I get: ORA-01006: bind variable does not exist
    I must use a PreparedStatement, as my variable may contain illegal characters (like '), and using PreparedStatement.setString(1, var) will automatically escape it for me.
    I could also use a normal Statement, but I need to escape my var ... is there a utility that will safely escape a String for an Oracle VARCHAR2??
    Thanks in advance,
    Stu Miller

    Hmm, it seems you are right...
    when my variable contains a '%' symbol, the PreparedStatement will NOT escape it, and thus it is treated like a wildcard. Therefore, I can just do
    pstmt.setString(1, var+"%");
    But, that may return more results than I'm asking for, as when 'var' contains a '%' symbol it is taken as a wildcard too.
    I need each character in my variable to be taken literally, and only add a wildcard at the end. Basically, I need a STARTSWITH operator ;-)
    It seems to me that escaping the sensitive characters in a String (which will differ depending on which operator is used), should be possible. I could write this, but I was hoping Oracle had already done it for me in some utility class.

  • How to use "scope " attrubute in useBean tag

    Can anyone please tell me if I can use the same JavaBean Class to hold information form different pages? well, let me explain exactely what I want to do:
    I have a Java bean Class that holds a property 'Name':
    package ContactManager;
    public class Person {
    private String name="%";
    public String getName () {
    return this.name;
    public void setName (String my_name) {
    name = my_name + "%" ;
    I'm using this class to store temporarly the Criteria of search from a JSP/HTML page to send to a database for search and for UPDATE -> this of course is done in different HTML/JSP pages. The problem I have is that the first time I set the properties (when the user make a search) this value remains unchanged [-> the second time when the user asks for update, I try to use the same bean to keep the value => unfortuntly it returns me the old value]
    My question is: is the use of 'scope' attribute of the "jsp:useBean" tag can solve this problem? if yes how to use it? I've tryed to set the scope of the bean to page but that does not help :-(
    Pleaze help, I'm stuck.... Bellow is the 4 JSP pages for:
    - person_search.jsp / person_result.jsp
    - request_modify.jsp/ DoModify.jsp
    1 -person_search.jsp
    <%@ page import="java.sql.*" %>
    <HTML>
    <HEAD><TITLE>Person Search</TITLE></HEAD>
    <BODY><CENTER>
    <form method="POST" action="person_result.jsp">
    Name <input type="text" name="name" size="47"></p>
    <input type="submit" value="Submit" name="B1">
    <input type="reset" value="Reset" name="B2"></p>
    </form></body>
    </html>
    2- person_result.jsp
    <%@ page import="java.sql.*" %>
    <HTML><BODY>
    <jsp:useBean id="theBean" class="ContactManager.Person"/>
    <jsp:setProperty name="theBean" property="*" />
    Name<BR>
    <%
    try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    System.out.println("JDBC driver loaded");
    catch (ClassNotFoundException e) {
    System.out.println(e.toString());
    %>
    <%
    try {
    Connection con = DriverManager.getConnection("jdbc:odbc:ContactManager");
    Statement s = con.createStatement();
    String sql = "SELECT Client.ClientID, Client.Name FROM Client where Client.Name like " + "'" + theBean.getName() + "'";
    ResultSet rs = s.executeQuery(sql);
    while (rs.next()) {
    String myId = rs.getString(1);
    %>
    <TR>
    <TD><%= myId %></TD>
    <TD><a href="person_detail.jsp?id=<%= myId %>"><%=rs.getString(2)%></a></TD>
    <TD><a href="delete_person.jsp?id=<%= myId %>">Delete</a></TD><BR>
    </TR>
    <%
    rs.close();
    s.close();
    con.close();
    catch (SQLException e) {
    System.out.println(e.toString());
    catch (Exception e) {
    System.out.println(e.toString());
    %>
    </BODY>
    </HTML>
    3- request_modify.jsp
    <%@ page import="java.sql.*" %>
    <html>
    <head><title>AddressBook: Modifying Person <%= request.getParameter ("id") %></title> </head>
    <body bgcolor="#ffffee">
    <%
    try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    System.out.println("JDBC driver loaded");
    catch (ClassNotFoundException e) {
    System.out.println(e.toString());
    %>
    <%
    int rowsAffected = 0;
    try {
    Connection con = DriverManager.getConnection("jdbc:odbc:ContactManager");
    Statement s = con.createStatement();
    String sql = "SELECT Client.ClientID, Client.Name FROM Client where ClientID ="+ request.getParameter("id");
    ResultSet rs = s.executeQuery(sql);
    if (rs.next()) {
    %>
    Client Name is <input type=text name=name value=<%= rs.getString(2) %>> <br>
    <TD><a href="person_do_modify.jsp?id=<%= rs.getString(1)%>">Confirm Modify</a></TD>
    <%
    rs.close();
    s.close();
    con.close();
    catch (SQLException e) {
    System.out.println(e.toString());
    catch (Exception e) {
    System.out.println(e.toString());
    %>
    </BODY> </HTML>
    4- do_modify.jsp
    <%@ page import="java.sql.*" %>
    <html>
    <head><title>AddressBook: Modifying Address <%= request.getParameter ("id") %></title></head>
    <body bgcolor="#ffffee">
    <jsp:useBean id="theBean" class="ContactManager.Person" scope="page"/>
    <jsp:setProperty name="theBean" property="name"/>
    <%
    try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    System.out.println("JDBC driver loaded");
    catch (ClassNotFoundException e) {
    System.out.println(e.toString());
    %>
    <%
    int rowsAffected = 0;
    try {
    Connection con = DriverManager.getConnection("jdbc:odbc:ContactManager");
    PreparedStatement preparedStatement = con.prepareStatement ("UPDATE Client SET Name=? WHERE ClientID =?");
    preparedStatement.setString (1, theBean.getName());
    preparedStatement.setString (2, request.getParameter("id"));
    rowsAffected = preparedStatement.executeUpdate ();
    preparedStatement.close ();
    if (rowsAffected == 1) {
    %>
    done
    <%
    else{
    %>
    Not Modified
    <%
    con.close();
    catch (SQLException e) {
    System.out.println(e.toString());
    catch (Exception e) {
    %>
    </BODY></HTML>
    Thank you for the help.
    Sammy

    While a quick search on the <jsp:useBean> tag and the scope attribute will probably yield more information than I can summarize in a few sentences, I'm pretty sure that using the scope="page" attribute on a bean will cause that bean to be instantiated every time the page is loaded. In order for a bean to persist longer than the existance of that page (whether you're loading a new page, or reloading the same one), you'd need to set the scope to session or application (you'd probably want session).

  • How to use Add Query Criteria for the MySQL data Base in Netbeans ?

    How to use Add Query Criteria for the MySQL data Base in Netbeans Visual web pack.
    When the Query Criteria is add like
    SELECT ALL counselors.counselors_id, counselors.first_name, counselors.telephone,counselors.email
    FROM counselors WHERE counselors.counselors_id = ?
    when i run this Query in the Query Window
    i get a error message Box saying
    Query Processing Error Parameter metadata not available for the given statement
    if i run the Query with out Query Criteria its working fine.

    *I am glad I am not the only one who have this problem. Part of issue has been described as above, there are something more in my case.
    Whenever I try to call ****_tabRowSet.setObject(1, userDropList.getSeleted()); I got error message as shown below:*
    The Java codes are:
    public void dropDown1_processValueChange(ValueChangeEvent event) {
    Object s = this.dropDown1.getSelected();
    try {
    this.User_tabDataProvider1.setCursorRow(this.User_tabDataProvider1.findFirst("User_Tab.User_ID", s));
    this.getSessionBean1().getTrip_tabRowSet1().setObject(1, s);
    this.Trip_tabDataProvider1.refresh();
    } catch (Exception e) {
    this.log("Error: ", e);
    this.error("Error: Cannot select user"+e.getMessage());
    SQL statement for Trip_tabRowSet:
    SELECT ALL Trip_Tab.Trip_Date,
    Trip_Tab.User_ID,
    Trip_Tab.Destination
    FROM Trip_Tab
    WHERE Trip_Tab.User_ID = ?
    Error messages are shown below:
    phase(RENDER_RESPONSE 6,com.sun.faces.context.FacesContextImpl@5abf3f) threw exception: com.sun.rave.web.ui.appbase.ApplicationException: java.sql.SQLException: No value specified for parameter 1 java.sql.SQLException: No value specified for parameter 1
    com.sun.rave.web.ui.appbase.faces.ViewHandlerImpl.cleanup(ViewHandlerImpl.java:559)
    com.sun.rave.web.ui.appbase.faces.ViewHandlerImpl.afterPhase(ViewHandlerImpl.java:435)
    com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:274)
    com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:140)
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
    org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:397)
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:184)
    com.sun.webui.jsf.util.UploadFilter.doFilter(UploadFilter.java:240)
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:216)
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:184)
    org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:216)
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:184)
    org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:276)
    org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
    org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:536)
    org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:240)
    org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:179)
    org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
    com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:73)
    org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:182)
    org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
    com.sun.enterprise.web.VirtualServerPipeline.invoke(VirtualServerPipeline.java:120)
    org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:939)
    org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:137)
    org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
    org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:536)
    org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:939)
    org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:239)
    com.sun.enterprise.web.connector.grizzly.ProcessorTask.invokeAdapter(ProcessorTask.java:667)
    com.sun.enterprise.web.connector.grizzly.ProcessorTask.processNonBlocked(ProcessorTask.java:574)
    com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.java:844)
    com.sun.enterprise.web.connector.grizzly.ReadTask.executeProcessorTask(ReadTask.java:287)
    com.sun.enterprise.web.connector.grizzly.ReadTask.doTask(ReadTask.java:212)
    com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:252)
    com.sun.enterprise.web.connector.grizzly.WorkerThread.run(WorkerThread.java:75)
    tandardWrapperValve[Faces Servlet]: Servlet.service() for servlet Faces Servlet threw exception
    java.sql.SQLException: No value specified for parameter 1
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
    at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:1674)
    at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:1622)
    at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1332)
    at com.sun.sql.rowset.internal.CachedRowSetXReader.readData(CachedRowSetXReader.java:193)
    at com.sun.sql.rowset.CachedRowSetXImpl.execute(CachedRowSetXImpl.java:979)
    at com.sun.sql.rowset.CachedRowSetXImpl.execute(CachedRowSetXImpl.java:1439)
    at com.sun.data.provider.impl.CachedRowSetDataProvider.checkExecute(CachedRowSetDataProvider.java:1274)
    at com.sun.data.provider.impl.CachedRowSetDataProvider.setCursorRow(CachedRowSetDataProvider.java:335)
    at com.sun.data.provider.impl.CachedRowSetDataProvider.setCursorIndex(CachedRowSetDataProvider.java:306)
    at com.sun.data.provider.impl.CachedRowSetDataProvider.getRowCount(CachedRowSetDataProvider.java:639)
    at com.sun.webui.jsf.component.TableRowGroup.getRowKeys(TableRowGroup.java:1236)
    at com.sun.webui.jsf.component.TableRowGroup.getFilteredRowKeys(TableRowGroup.java:820)
    at com.sun.webui.jsf.component.TableRowGroup.getRowCount(TableRowGroup.java:1179)
    at com.sun.webui.jsf.component.Table.getRowCount(Table.java:831)
    at com.sun.webui.jsf.renderkit.html.TableRenderer.renderTitle(TableRenderer.java:420)
    at com.sun.webui.jsf.renderkit.html.TableRenderer.encodeBegin(TableRenderer.java:143)
    at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:810)
    at com.sun.webui.jsf.component.Table.encodeBegin(Table.java:1280)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:881)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:889)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:889)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:889)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:889)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:889)
    at com.sun.faces.application.ViewHandlerImpl.doRenderView(ViewHandlerImpl.java:271)
    at com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:182)
    at com.sun.rave.web.ui.appbase.faces.ViewHandlerImpl.renderView(ViewHandlerImpl.java:285)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:133)
    at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:244)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:140)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
    at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:397)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:184)
    at com.sun.webui.jsf.util.UploadFilter.doFilter(UploadFilter.java:240)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:216)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:184)
    at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:216)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:184)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:276)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:536)
    at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:240)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:179)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:73)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:182)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
    at com.sun.enterprise.web.VirtualServerPipeline.invoke(VirtualServerPipeline.java:120)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:939)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:137)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:536)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:939)
    at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:239)
    at com.sun.enterprise.web.connector.grizzly.ProcessorTask.invokeAdapter(ProcessorTask.java:667)
    at com.sun.enterprise.web.connector.grizzly.ProcessorTask.processNonBlocked(ProcessorTask.java:574)
    at com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.java:844)
    at com.sun.enterprise.web.connector.grizzly.ReadTask.executeProcessorTask(ReadTask.java:287)
    at com.sun.enterprise.web.connector.grizzly.ReadTask.doTask(ReadTask.java:212)
    at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:252)
    at com.sun.enterprise.web.connector.grizzly.WorkerThread.run(WorkerThread.java:75)
    Also when I tried to update my MYSQL connector / J driver to version 5.1.5 from 5.0.5 (NB 5.5.1) and 5.0.7 (NB 6.1), I could not get it work (looooong time to search some JDBC classes and with no response in the end) on both of my Netbean 5.5.1(on PC) and Netbean 6.1(on laptop) IDEs.
    Could anybody look into this issue.
    Many thanks
    Edited by: linqing on Nov 22, 2007 4:48 AM

  • How to print PreparedStatment object in console

    Dear All
    i am using PreparedStatment for inserting data into a table, in my local system it is working fine, but after deploying in JBoss(Server) it is throwing "invalid column type" error. In order to check i tried to print in the JBoss console but i am unable print in the console, kindly help me regarding this.
    The code which i used is:
    PreparedStatement stmtPrep = conn.prepareStatement(sql);
    try {
    stmtPrep.setObject(1, number);
    stmtPrep.setObject(2, (String) passList.get("PlantCode"));
    stmtPrep.setObject(2, (String) passList.get("PlantExt"));
    stmtPrep.setObject(3, ls_per_ord_qty_ind);
    stmtPrep.setObject(4, ls_price);
    stmtPrep.setObject(5, (String) inList.get(4));
    stmtPrep.setObject(6, (String) List.get("txtStoreLoc"));
    stmtPrep.setObject(7, (String) List.get(1));
    h = (String) List.get("Price");
    float unit = Float.valueOf(h.trim()).floatValue();
    stmtPrep.setFloat(8, unit);
    System.out.println(">>>Query is>>>>>"+stmtPrep);
    Can any one guide me how to print in JBoss console this stmtPrep and check all the values that i am passing r correct r not.
    but it is throwing like this:
    15:16:30,686 INFO [STDOUT] >>>Query is>>>>>org.jboss.resource.adapter.jdbc.Wrap
    pedPreparedStatement@1056bdd

    sasikrishna wrote:
    Dear All
    i am using PreparedStatment for inserting data into a table, in my local system it is working fine, ok.
    but after deploying in JBoss(Server) it is throwing "invalid column type" error. That would seem to be a database problem to me. Schema specifically.
    In order to check i tried to print in the JBoss console but i am unable print in the console, Why does it matter since it will not help you?
    Your code specifically details the object types that you are setting.
    Presumbly the 'sql' is just a hard coded value.
    Consquently the conclusion is that the database on your local box versus the deployment is different. And nothing that you print in JBOSS will help you discover what the difference is. You need to look at the 'sql' and determine the entities from that and then compare them in the schema for both places.
    check all the values that i am passing r correct r not.As noted if that isn't a security violation for your application then you are left with the following.
    - Drivers do not necessarily create SQL.
    - If they do AND the driver is up to date then there is a method (look for it in the javadocs) that will return it
    - If not you should use a jdbc wrapper proxy that consumes the data for you. This might be better even if the driver does it.

  • How to use PooledConnection

    Hi all
    This problem can look funny to lot of you.
    I have project where i use Java on server side to perform some operation with MySQL. I have created connection to MySQL but there will be lot of users and connecting to database like i have done is not a option.
    public Connection Connecting() {         try {             String username = "username";             String password = "pass";             String url = "jdbc:mysql://localhost:3306/database";             Class.forName("com.mysql.jdbc.Driver").newInstance();             conn = DriverManager.getConnection(url, username, password);             System.out.println("Connection established on connecting to database");         } catch (Exception e) {             System.out.println("Database Connection Problem while creating connection:" + e);         }         return conn;     }
    Then i was informed that i can use Pooled Connection. From NetBeans tutorial i have learn how to create it.
    [http://www.netbeans.org/kb/60/web/mysql-webapp.html|http://www.netbeans.org/kb/60/web/mysql-webapp.html]
    There i nice explanation how to create server resource and how to use it directly on web page.
    <sql:query var="subjects" dataSource="jdbc/IFPWAFCAD">     SELECT subject_id, name FROM Subject </sql:query>
    But i need to use it in my Java class. How to use PooledConnection created on server (GlassFish)
    I was checking lot of web pages and all was talking about how to create PooledConnection but nothing with example how to use PooledConnection created on server already.
    If any one can give some code example.
    I have also checked this but i don't get it how to get data?
    [http://java.sun.com/j2se/1.4.2/docs/api/javax/sql/PooledConnection.html|http://java.sun.com/j2se/1.4.2/docs/api/javax/sql/PooledConnection.html]

    You use the DataSource to get connections (by calling getConnection()). "jdbc/IFPWAFCAD" is the JNDI name for your resource and you use that to get the actual DataSource object that the container should've loaded for you. So you get the DataSource by it's JNDI name and then get connections from the DataSource. Once you have a Connection, you can do all the stuff you'd normally do with JDBC, using PreparedStatements etc.
    It's is advisable to use a DAO in order to separate your business logic from your data access logic. Check out this tutorial: [http://balusc.blogspot.com/2008/07/dao-tutorial-data-layer.html]

  • How to use I18N in Oracle's queries

    Hi guys. I want to know how I can internationalize the date conversion in my SQL queries, stored procs, and triggers (from here known as queries) in Oracle. Currently, what we do to convert chars to dates is "to_date('mm/dd/yyyy', dateParam)'. This have been working fine until recently when we decided to internationalize our app that the "dateParam" we passed to the queries does not necessarily follow the "mm/dd/yyyy" format anymore.
    Any help would be greatly appreciated. Thanks.

    You should be using PreparedStatements and bind variables and then there would be no problem.
    If not your database only supports a single time format.
    So your java code must convert to that format first before calling the SQL. You can use SimpleDateFormat and specify the TimeZone when you call it.

  • Queries with date functions using PreparedStatement for multiple DB

    I am developing application that uses DB independant queries. I am using preparedstatement to process the queries. I need to use date functions for query selection criteria.
    for eg.
    selecting the list of employees who had joined in the last 15 days
    selecting list of employees who had joined between two dates etc.
    where Date Joined field is a Timestamp value. To extract date no DB specific function can be used.
    If I use setMonth, setYear etc.. to set params in the pstmt the query becomes complex in the above case. Can any one throw some light on how to do the above in preparedstatement or any other better alternative.
    Tx a lot

    Hi,
    I did not mean that way. I presume that there is a timestamp value (may be a date too) column in the table. Then based upon your requirement (say before 15 days) pass the value as date (or time stamp) in the query as a parameter.
    String qry = "select * from myTable where join_date <= ?";
    stmt.setDate(1,myDate); // this is where you will have to manipulate the value to suit your DB timestamp or date value; you will have compatibility issues with util.Date and sql.Date so use Calendar class to satisfy.Feel free to mail me if you need further clarifications to [email protected]
    Cheers,
    Sekar

  • Conditinal update using PreparedStatement

    Hi,
    I have situation where in I need to create dynamic sql statements based on user input.
    let's say user changes his last name or only first name or some comments field only those fileds changed should be updated in database leaving rest un changed.
    I am using PreparedStatement to update (this switched to over come single quote issue with oracle).
    if it was simple insert/update i could user statements but how can I do conditinal update using one prepared statement?
    any help

    From what I've read in the docs and experienced with Oracle drivers, it can't be done. The only way to dynamically create a prepared statement would be to create an update string conditionally based on the changed inputs, then create the PreparedStatement after the conditional checks(same technique you would use to dynamically create a Statement). But that doesn't really fit the criteria laid out by your initial post(only one PreparedStatement for all conditions).
    You could also use the CallableStatement and generate your update statement in the CallableStatement the same way you would generate the UPDATE dml using a Statement?
    Jamie

  • Code using PreparedStatement.executeUpdate failing in stress test

    Hello,
    I've just recently learned how to use J-Meter and have been performing tests on my programs. One of which performs the following:
    1. Read user data using a simple SELECT password FROM users where userid = 'xxx'
    2. When authenticated, runs an immediate update using value binding via PreparedStatement.executeUpdate() which is really just updating the lastlogin column of the same table with the current date.
    My application servlet is running on Glassfish and uses a jdbc connection pool defined on it. The problem is that at about 200 concurrent executions per second of the process described above, PreparedStatement.executeUpdate() returns 0 instead of 1 at around 20% of the time. The Glassfish server is on a Sunfire X2100 platform running solaris 10 and has 2 gb ram, while the database on the other end is a Oracle 10G R2 on a PC clone Pentium 4 with 512mb ram also running on Solaris 10.
    This failure rate is too high so what can I do to reduce it?
    Thanks in advance,
    - Owen

    Owen_Ilagan wrote:
    Hello,
    200 per second? That's a pretty decent load. Well, I was told that that was the acceptable load for the same app running on a standard pentium 4 machine I don't see how you can talk about "acceptable load" for a given piece of hardware without taking into consideration what the application is doing. A read-mostly web app will be very different from one that's transaction and/or computation intensive.
    so I would like to get better performance from this Sunfire X2100. Unless of course that figure is wrong... I've just recently started learning to scale my java applications and figuring out how to fine-tune the servers my programs would be running on. I think this is a good article:
    http://www.javaworld.com/javaworld/jw-06-2006/jw-0619-tuning.html?page=1
    I don't know where that setting is on Glassfish so its on default. Is there an optimal setting for it? I run JMeter on a different machine. Good - your clients aren't competing for memory with the server that way.
    Again, I dont seem to recall seeing a setting like that on Glassfish. The current pool setting is at Initial size 8, maximimum size of 32. I already tried increasing it to 200+ but there was no noticeable improvement so I set it back to 32. That's sufficient. You don't need 1 connection per user because of the pool. I use 5:1 as a rule of thumb.
    Threads in my worker pool? Hmmm, let me just clarify that I'm running a rather simple web servlet application using the 1.5 SDK and its not a full-blown EE application. Doesn't matter. There is one thread per incoming request. If the worker thread pool is exhausted the requests are queued up. There's an optimal setting for that, too.
    Well, I dont run into any SQL errors so there is no stack trace to log. Huh? You mean your PreparedStatement can return 0 and not have an exception?
    What happens if you try to UPDATE a user record that isn't in the database? Is that possible?
    When PreparedStatement.executeUpdate() is called, it returns 0 instead of 1. I did put the call inside a try-catch to handle java.sql.SQLExceptions but its not throwing one.Interesting. See question above.
    I hope so.Difficult, but you sound like you're doing a rigorous job.
    %

  • Update using preparedstatement

    Hi
    I am using preparedstatement to fire insert / update statements.
    the update query is taking a lot of time(min 150 ms) where as the insert query takes 0 ms .
    i'm using mssql driver with sql2000.
    what might be the problem???
    Regards
    Ravi

    in case of static the index costs only 38% where as in
    case of dynamic query the index costs 96%
    tht's the reason the dynamic query is taking more time
    also in case of static INDES SEEK is used where as in
    case of dynamic execution INDDEX SCAN is used so
    INDEX SEEK gets the record in one attempt where as
    indexscan scans the whole table to get the record so
    the row count in this case is same as the no of
    records in that table.
    now the question is how can i change the data access
    path /execution plan for the dynamic execution so that
    it should also look for index seek instead of index
    scan.Just to be clear, your Statement query is dynamic, while your PreparedStatement is static. In a previous post you implied that Statement was taking longer, but in this note you are implying that the PreparedStatement is taking longer. I'll let you work out which is which, but it appears that it is in fact a difference in the data access path that is causing the decreased performance.
    I am not a SQL Server expert by any means, but it is possible that someone else can provide you some specific suggestions on what to do next. I am curious why you want to use a Statement vs PreparedStatement (or vice versa). There have been multiple posts discussing the differences and in most cases from a programmers perspective PreparedStatements are superior because they automatically manage many of the data transformations for you (like escape characters for quotes). PreparedStatements are usally recommended by the DBA when a SQL is going to run repeatedly and frequntely to avoid having the database to re-parse the SQL all the time. Having said that, there are still many cases where using dynamc SQL makes sense and yours may be one of these (not sure).
    So, anybody with strong SQL Server have any suggestions for the OP?
    You may want to post this specific performance question out to a SQL Server forum too...

  • Using PreparedStatement to execute a SQL Query

    hi All,
    I am trying to use PreparedStatement to execute a Query in Java.
    The Problem is that where Clause of that Query is dynamically formed as per
    user inputs .
    So , in this case will it help if I use PreparedStatement in place of Normal Statement ?
    If Yes , then how to handle the Dynamic where clause of the Query ?
    Thanks in Advance.
    Regards,
    ninad

    Let's say the user is providing a name, and you'r querying based on that name: PrepartedStatement ps = con.prepareStatement("select * from my_table where name = ?);
    ps.setString(1, nameFromUser);
    ResultSet rs = ps.executeQuery();
    http://java.sun.com/developer/onlineTraining/Database/JDBC20Intro/

  • How to use a variable where some Java API expects an integer value ???

    Hi all,
    This may not be a proper forum to submit this query but since its a Java related problem & there are many experience people, I hope I can get some good hint and advice to solve this problem.
    I have to pass an integer value to a SPARQL query. I am using Allegrograpg API for Java application. But I am receiving the value in a variable and query accepts it as an integer. How can this kind of problem be solved. I put query under so you can see it.
    " SELECT DISTINCT ?Pattern ?Model WHERE" +
    "{ ?class rdfs:subClassOf [ owl:onProperty :locationID; " +
    " owl:hasValue \"1000\"^^xsd:int ]."+........
    The query expects an integer as has value.
    My apology again for posting it here but since its a Java releted problem, I hope some body can give me some good advice.....

    Ahhh, I don't think it is so terrible, it just depends where from is coming the variable that you are interpolating.
    The main reason for using PreparedStatement is efficiency. If you want to be safe from SQL injection you just have to do a simple REGEX substitution over the SQL string.
    --janeiros                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Maybe you are looking for

  • Can't get iPad to play iTunes Library from LaCie Fuel

    Hi All, First time poster here so I hope I'm posting in the right section! I bought a Lacie Fuel specifically for my husband to be able to access our iTunes library when he's off working at remote sites for weeks on end. I followed all the instructio

  • Contacts and Calendar have disappeared from iPhone

    All my contacts and calendar entries have totally disappeared from my iPhone on 20.5.09. My free trial of MobileMe was due to end on 20.5.09, so on 17.5.09 I cancelled my subscription (didn't really use it). The only backup of my contacts/calendar wa

  • Problem in signal processing

    Hello all, I use LabVIEW 8.2 student edition. I have the problem to split the output of FFT. The harmonic component has more then one output: Can I get only one of the component in harmonic component? I mean, in the result picture, there are three ou

  • Formsweb.cfg probelm, after addion of the new applicaiton enty........

    Dear All We are getting strange problem. When we add new application entry in formsweb.cfg in Oracle 9i AS 9.0.2.0.1. And when we access it on IE it doesnt work it show the follwoing error in java console.... We appreciate every one who want to resol

  • App for creating .ico files???

    I am looking for an app to create the .ico files that are used as the image for bookmarks. Anybody know any good OS X apps for this???