Results 1 to 4 of 4
  1. #1
    wickedrahul9 is offline Member
    Join Date
    Jul 2008
    Posts
    8
    Rep Power
    0

    Default Not able to delete MSSql database table entries

    The purpose of this program is to delete all entries of database table which has 1 column. I have used MSSql database server. When I run this program it's taking infinite time to process. There are only 10 entries in table.

    I'm not able to figure out what's wrong with my code. Anybody could please help me out ?

    index.jsp
    --------

    <script type="text/javascript">
    function disp_confirm()
    {
    var r=confirm("Press Ok to proceed & Cancel to stop");
    if (r==true)
    {

    window.location="flush.jsp";
    }
    else
    {
    window.location="index.jsp";
    }
    }
    </script>

    <form name="form" action="flush.jsp" method="POST">
    <input type="button" onclick="disp_confirm()" value="Flush yesterday's sent emails" />
    </form>


    flush.jsp
    ---------

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <%@ page import="java.sql.Connection" %>
    <%@ page import="java.sql.Statement" %>
    <%@ page import="java.sql.ResultSet" %>
    <%@ include file = "inc_SettingGlobalDbConnectionsRahul.jsp" %>
    <%@ include file = "inc_SettingGlobalParams.jsp" %>

    <title>JSP Page</title>
    </head>
    <body>
    <%
    Connection db_connection = null;
    Statement db_statement = null;
    Statement db_statement_today = null;
    Statement db_statement_update = null;

    try {
    db_connection = connect(serverName, databaseName, userName, password);
    String checkData = "delete from table_email_today";
    db_statement = connection.createStatement();
    db_connection.setAutoCommit(false);

    ResultSet resultSet = db_statement.executeQuery(checkData);
    if (!resultSet.next())
    {
    out.println("<center><b>No unsub. email<b></center>");
    }
    else
    {
    while (resultSet.next())
    {
    out.println(resultSet.getString(1));
    }
    }
    resultSet.close();

    db_connection.commit();
    db_connection.setAutoCommit(true);
    db_statement.close();
    db_statement_today.close();
    db_statement_update.close();
    db_connection.close();
    }

    catch (Exception ex)
    {
    out.println("Error : " + ex);
    }

    %>
    </body>
    </html>


    inc_SettingGlobalDbConnectionsRahul.jsp
    -------------------------------------------

    <%@ page import="java.sql.*" %>
    <%!
    public Connection connection = null;
    public Connection connect(String server,String database,String userName,String password ) throws Exception
    {
    String fullConnectionString = "jdbc:odbc:DRIVER={SQL Server};Database="+database+";Server="+server+";";
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    connection = DriverManager.getConnection(fullConnectionString,u serName,password);
    return connection;
    }
    %>


    inc_SettingGlobalParams.jsp
    ---------------------------

    <%!

    public static String serverName = "localhost";//Name of your server
    public static String databaseName="co";//Name of your database
    public static String userName = "sa";//UserName to connect
    public static String password ="sa";//passwords to connect

    %>

  2. #2
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    7

    Default

    What error do you get?

  3. #3
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    7

    Default

    put System.println statements in it, scatter them about, with unique strings. See where it is looping.

    Then go into the looping code with more System.println statements, and find exactly which line(s) is causing the problems. Fix your bugs

  4. #4
    wickedrahul9 is offline Member
    Join Date
    Jul 2008
    Posts
    8
    Rep Power
    0

    Default

    I got the solution . When I am deleting all the entries of database table I should have used executeUpdate & not executeQuery :p

Similar Threads

  1. Updating database table from JTable
    By yesjava in forum New To Java
    Replies: 1
    Last Post: 08-16-2008, 10:16 PM
  2. Replies: 0
    Last Post: 03-29-2008, 03:36 PM
  3. Replies: 0
    Last Post: 02-09-2008, 08:31 PM
  4. Replies: 0
    Last Post: 02-09-2008, 08:22 PM
  5. Replies: 1
    Last Post: 02-01-2008, 01:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •