Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Java with Database

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java with Database

    Hi

    I have made I database to my program and need to call a sql statment that sends back from the database that it has that numbers of "xxx", want a main class and a gui with it if you know how to
    please write asap.


    to my java code
    public class library2 {
     
    	private Connection connect = null;
    	private Statement statement = null;
    	private ResultSet resultSet = null;
     
    	public void readDataBase() throws Exception {
     
    			Connection con = null;
    			Statement st = null;
    			ResultSet rs = null;
     
    			try {
    				Class.forName("com.mysql.jdbc.Driver").newInstance();
    				con = DriverManager.getConnection("jdbc:mysql:///librarydb",
    						"root", "123123");
     
    				st = con.createStatement();
    				rs = st.executeQuery("SELECT firstName, address, FROM customer");
     
    				while(rs.next()) {
    					int userId = rs.getInt(1);
    					String firstName = rs.getString(2);
    					String address = rs.getString(3);
     
    					System.out.println(userId + ". " + address + ", " +
    							firstName);
    				}
     
    			} catch (Exception e) {
    				System.err.println("Exception: " + e.getMessage());
    			} finally {
    				try {
    					if(rs != null)
    						rs.close();
    					if(st != null)
    						st.close();
    					if(con != null)
    						con.close();
    				} catch (SQLException e) {
    				}
    			}
    		}
    	}


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Java with Database

    want a main class and a gui with it if you know how to
    If you are asking some one to write code for you, you're at the wrong place.
    If you have code with problems, please ask some questions about your problems and post the code to show what you have done.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Dec 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java with Database

    Was asking how to do it ??

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Java with Database

    If you don't know how to write a GUI in Swing, a good place to start is to read the tutorial:
    Trail: Creating a GUI With JFC/Swing (The Java™ Tutorials)
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Need help in java database application.
    By deepaksinghkushwah in forum JDBC & Databases
    Replies: 1
    Last Post: December 5th, 2012, 10:02 AM
  2. Trying to connect to a sample Java DB database
    By matt0605 in forum JDBC & Databases
    Replies: 4
    Last Post: October 10th, 2012, 07:38 AM
  3. database for use in java
    By umerahmad in forum JDBC & Databases
    Replies: 7
    Last Post: November 6th, 2011, 07:07 AM
  4. java database
    By ronaldguilmet in forum JDBC & Databases
    Replies: 7
    Last Post: November 4th, 2011, 11:37 AM
  5. connect java to a database
    By ridg18 in forum JDBC & Databases
    Replies: 1
    Last Post: December 25th, 2010, 11:28 AM