Results 1 to 6 of 6
  1. #1
    madhav.dubey9 is offline Member
    Join Date
    Jan 2013
    Posts
    25
    Blog Entries
    1
    Rep Power
    0

    Default updating data in SQL SEVER database using JDBC

    I might sound silly but yet i m stuck into a problem in which i need to update my table in data base and when i use updateRow() method the whole java application stops working and do not respond.Please help me through this.

  2. #2
    SnakeDoc is offline Senior Member
    Join Date
    Apr 2012
    Posts
    129
    Rep Power
    0

    Default Re: updating data in SQL SEVER database using JDBC

    it sounds like its hanging because it's either in some loop and can't break out (updating a ton of records?) or there is a problem with your connection (although it should timeout after some period of time).

    What database are you working with? What JDBC driver are you using? What does your query look like? Are you using Statements or PreparedStatements? Please elaborate. thanks.

  3. #3
    madhav.dubey9 is offline Member
    Join Date
    Jan 2013
    Posts
    25
    Blog Entries
    1
    Rep Power
    0

    Default Re: updating data in SQL SEVER database using JDBC

    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connectio con=DriverManager.getConnection("jdbc:odbc:stdsn", "user", "password");
    Statement stmt=con.createStatement(ResultSet.TYPE_SCROLL_SEN SITIVE,ResultSet.CONCUR_UPDATABLE);
    ResultSet rs=stmt.executeQuery("select * from QUES");
    .
    .
    .
    rs.updateString(2,"xxx");

    till this it is working fine..but when i need to make changes in database itself i use rs.updateRow() .As soon as this method is called the application hangs up.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,406
    Rep Power
    20

    Default Re: updating data in SQL SEVER database using JDBC

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,086
    Rep Power
    20

    Default Re: updating data in SQL SEVER database using JDBC

    Don't use the JDBC-ODBC bridge. SQL Server has a perfectly good driver of its own designed to be used with it.

    I shudder when people use SCROLL_SENSITIVE, especially with updateable. And I suspect that is your problem, possibly down to the bridge being unable to handle it? Why do you need to have this as updateable? That's usually a sign of poor design decisions, especially from posts in the New To Java section.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    SnakeDoc is offline Senior Member
    Join Date
    Apr 2012
    Posts
    129
    Rep Power
    0

    Default Re: updating data in SQL SEVER database using JDBC

    I agree with Tolls, you're using JDBC in a strange way to me... most definitely a way I wouldn't go about this (that doesn't mean it's wrong, just different).

    Here's how I normally would connect to SQL Server:

    Java Code:
    public static void main(String[] args) {
    	Connection conn = DriverManager.getConnection("jdbc:sqlserver://" + "127.0.0.1/somedb:9999", username, password);
    
    	String sql = "SELECT * FROM ques";
    
    	try {
    		PreparedStatement ps = conn.prepareStatement(sql);
    
    		ResultSet rs = ps.executeQuery();
    
    		while (rs.next()) {
    			System.out.println(rs.getString(1));
    		}
    
    	} catch (SQLException e) {
    		e.printStackTrace();
    	} finally {
    		conn.close();
    	}
    }
    This requires the Microsoft SQL Server JDBC driver: Download Microsoft JDBC Driver 4.0 for SQL Server from Official Microsoft Download Center

    JDBC 4.0 drivers do not require the Class.forName() syntax. :)

    You can create several prepared statements if you like, one for selecting data, one for updating data, etc. when doing an update query, i'd recommend using the .executeUpdate(); syntax, since this will return the number of rows effected via a ResultSet after each UPDATE query. This is helpful in determining if your query was successful or not.

    Are there some specific requirements that make you do your queries the way you are going about it? (ODBC instead of direct access, etc...)

Similar Threads

  1. Updating Ms Access Database using jsp
    By gauravmanral in forum JavaServer Pages (JSP) and JSTL
    Replies: 7
    Last Post: 07-01-2012, 06:07 PM
  2. Updating SQL database
    By dragon_baby in forum New To Java
    Replies: 4
    Last Post: 06-17-2012, 03:47 PM
  3. Problem updating access database from jsp
    By Penhexy in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 03-17-2011, 08:50 AM
  4. Prob with updating in jdbc
    By venkatteshb in forum New To Java
    Replies: 4
    Last Post: 08-21-2008, 06:08 PM
  5. Updating database table from JTable
    By yesjava in forum New To Java
    Replies: 1
    Last Post: 08-16-2008, 10:16 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
  •