The Artima Developer Community
Sponsored Link

Java Answers Forum
I need an example of a query in Java

8 replies on 1 page. Most recent reply: Jan 6, 2004 1:18 PM by s

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 8 replies on 1 page
Delie

Posts: 12
Nickname: tuti
Registered: Oct, 2003

I need an example of a query in Java Posted: Dec 16, 2003 5:10 AM
Reply to this message Reply
Advertisement
Hi, do someone have an example of a query in Java.If so please send it to me, maybe it can help me solve my problem with my queries.
Thanks


s

Posts: 23
Nickname: codemonkey
Registered: Nov, 2003

Re: I need an example of a query in Java Posted: Dec 16, 2003 7:59 AM
Reply to this message Reply
You no makey sensey...
an SQL query? if so a query that does what?

Delie

Posts: 12
Nickname: tuti
Registered: Oct, 2003

Re: I need an example of a query in Java Posted: Dec 16, 2003 8:24 AM
Reply to this message Reply
For example a query that checks if the username the user entered matches with the one in the database. I think my question makes sense, because java uses a different syntax (a few things) for queries. If you have one post it to me...thank you.

s

Posts: 23
Nickname: codemonkey
Registered: Nov, 2003

Re: I need an example of a query in Java Posted: Dec 16, 2003 12:03 PM
Reply to this message Reply
Trust me ...youre not making alot of sense ...in one post youre talkin about QueryDataSets...do you mean ResultSets?
basically i think you want to know how to use jdbc functionality to query a database table? if thats the case
heres a little snippet of code and there are plenty of
easy to follow tutorials out there :

   public void initDBConnection(){
        try {	    
	    Class.forName("org.gjt.mm.mysql.Driver").newInstance(); 
	    
	}
	catch (Exception e) {
	    System.err.println("Unable to load driver.");
	    e.printStackTrace();
	}
 
	try {
	    conn = DriverManager.getConnection(getConnectString());
	 
	}catch (SQLException sqle) {
	    System.out.println("SQLException: " + sqle.getMessage());
	    System.out.println("SQLState:     " + sqle.getSQLState());
	    System.out.println("VendorError:  " + sqle.getErrorCode());
	    sqle.printStackTrace();
	}
		
    }
 
   public String performQuery(String query){
	StringBuffer results = new StringBuffer();
	try{
	    Statement stmt = conn.createStatement();
	    ResultSet rs = stmt.executeQuery(query);
	    ResultSetMetaData rsmd = rs.getMetaData();
	    int colcnt = rsmd.getColumnCount();
	    while(rs.next()){
		for(int g=1;g<=colcnt;g++){
		    results.append(rsmd.getColumnName(g)+" :");
 
		    results.append(rs.getString(g)+"\n");
		    
		}//for
		results.append("+++++++++++++++++++++++++++++++++++++++++++\n");
		
	    }//while
	}catch (SQLException sqle) {
	    System.out.println("SQLException: " + sqle.getMessage());
	    System.out.println("SQLState:     " + sqle.getSQLState());
	    System.out.println("VendorError:  " + sqle.getErrorCode());
	}
	if(results.length()==0){results.append("NO RESULTS");}
	return results.toString();
	
    }
 


Im not going to give you a complete tutorial on sql...
the query parameter here may be something like
"SELECT * from lusers WHERE luser_name='Delie'"

Anyways why dont you be more specific and we'll see if we can help you... maybe even post some code that we can see...

Questions like "how do i use xml?",
"how do i do a a query?","will you do my homework for me?",
"how do i write a scientific calculator?" etc..
are either too vague or demonstrate a complete unwillingness to help yourself...if you want real/detailed help pose your questions with real details...and show/tell us the things youve tried already to solve the problem...and what happened
with those efforts etc..post code and error messages...
ok thats the end of my rant lol


The mad code monkey.

Delie

Posts: 12
Nickname: tuti
Registered: Oct, 2003

Re: I need an example of a query in Java Posted: Jan 6, 2004 8:25 AM
Reply to this message Reply
Ok, here is the query i made, but i don't know if it works. The connection to the db exists, but it won't execute. To make it clearer it doesn't reach the line "qdsUser.executeQuery();".

I hope i am clearer know,

thank you!

//check validation of username and password in db

QueryDataSet qdsUser= new QueryDataSet();
qdsUser.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(databaseOne,
"SELECT USERNAME from USER WHERE USER.\"USERNAME\"=" +username+
"AND USER.\"PASSWORD\"=" +password+" ", null, true,Load.ALL));

qdsUser.executeQuery();

s

Posts: 23
Nickname: codemonkey
Registered: Nov, 2003

Re: I need an example of a query in Java Posted: Jan 6, 2004 10:15 AM
Reply to this message Reply
Ok ...i'll bite...
what is a QueryDataSet?

s

Posts: 23
Nickname: codemonkey
Registered: Nov, 2003

Re: I need an example of a query in Java Posted: Jan 6, 2004 10:21 AM
Reply to this message Reply
Could you also post the errors/exceptions you get ...?

Kelly R. Denehy

Posts: 8
Nickname: kdenehy
Registered: Dec, 2003

General guideline - do a little research before posting questions Posted: Jan 6, 2004 12:25 PM
Reply to this message Reply
http://groups.google.com/groups?q=QueryDataSet&ie=UTF-8&oe=UTF-8&hl=en&btnG=Google+Search

s

Posts: 23
Nickname: codemonkey
Registered: Nov, 2003

umm Posted: Jan 6, 2004 1:18 PM
Reply to this message Reply
ok ....whats yer f-cking point kelly?
you know what go troll somewhere else....moron...

Flat View: This topic has 8 replies on 1 page
Topic: very urgent - drawing graphs using java swings Previous Topic   Next Topic Topic: final, finally and finalize

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use