• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Query doesn't working with JDBC in Java

 
vinoth vino
Ranch Hand
Posts: 67
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well i don't know about sql a lot and Now i m learning JDBC,



OUTPUT
1 Vino 18
2 Mano 19
3 Gopal 24
4 Naveen 16
5 Praveen 22


My Doubt is,
1. Here, i can't get the result for query that i've documented in the ResultSet interface. i did "select name,age from emp1" but for me it gives exception...
2. Then what is the difference betweent statement and resultset ?
3. What is Query ?
4. Where these JDBC's are used in real life scenario ?
5. Here, What is the front end and back end applications ? java(JDBC) is frontend and Mysql is backend software right?
 
Campbell Ritchie
Sheriff
Posts: 51456
87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is wrong with that oiutput? What exception? What were its message and error code? Have you read the Java™ Tutorials section about JDBC?
 
vinoth vino
Ranch Hand
Posts: 67
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


OUTPUT
java.sql.SQLException: Column Index out of range, 3 > 2.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:998)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:937)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:872)
at com.mysql.jdbc.ResultSetImpl.checkColumnBounds(ResultSetImpl.java:764)
at com.mysql.jdbc.ResultSetImpl.getInt(ResultSetImpl.java:2471)
at demojdbc.MysqlCon.main(MysqlCon.java:31)


What's wrong with my code ?
and please clarify my doubts too

My Doubt is,
1. Here, i can't get the result for query i did "select name,age from emp1" but for me it gives exception...
2. Then what is the difference betweent statement and resultset ?
3. What is Query ?
4. Where these JDBC's are used in real life scenario ?
5. Here, What is the front end and back end applications ? java(JDBC) is frontend and Mysql is backend software right?
error.png
[Thumbnail for error.png]
 
Campbell Ritchie
Sheriff
Posts: 51456
87
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you asking for two columns and trying to read the third column?
 
Liutauras Vilda
Bartender
Pie
Posts: 2803
112
BSD VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Decrement numbers by 1, which are being passed as arguments of columns. As you been already told, your ResultSet rs contains 2 columns. Name is 1st one, Age is 2nd.

[edit]
Also, create methods to separate connection and querying. And probably for printing result.
 
vinoth vino
Ranch Hand
Posts: 67
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I m sorry i didn't see that clearly at that moment. Anyways Thanks a ton....
Please clarify these below doubts too
1. Then what is the difference betweent statement and resultset ?
2. What is Query ?
3. Where these JDBC's are used in real life scenario ?
4. Here, What is the front end and back end applications ? java(JDBC) is frontend and Mysql is backend software right?
5. Difference between ResultSet.TYPE_FORWARD_ONLY,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.TYPE_SCROLL_SENSITIVE ?
6. Difference between ResultSet.CONCUR_READ_ONLY,ResultSet.CONCUR_UPDATABLE ? (Here, I know little bit of these concurrency of resultset. I'll tell what i knew,ResultSet.CONCUR_READ_ONLY it will read only here no modifications are performed. Then ResultSet.CONCUR_UPDATABLE means here we can modify anythings like creating table,updating table,modifying table) is this necessary to implement when creating statements ? without this what i can able to do ? Only "select query" will work or i can able to create,update,drop the table ?

I saw these resultset types and concurrency in java doc but i can't understand it clearly.Please makes me to understand it
Kindly please ignore it i need to know pleaseeeeeeee
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic