This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

retrieve data from database

 
Faisal Shahzad
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

i want to search data from database connected through Class.forName("sun.jdbc.odbc.JdbcOdbcDriver") . through this app successfully data saved into database when i search data from database it show this message " java.sql.sqlexception driver does not support this function " here is mine code for search . please any one help me.

private void SerchbuttonActionPerformed(java.awt.event.ActionEvent evt) {
try{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

String url = "jdbcdbc:ProductDSN";

Connection conn = DriverManager.getConnection(url,"","");

Statement st = conn.createStatement();

String sql = "SELECT * FROM ProductDb WHERE id=?";

java.sql.PreparedStatement pst =conn.prepareStatement(sql);
pst.setString(1, search.getText());
ResultSet rs = pst.executeQuery(sql);
if(rs.next()){
String add1=rs.getString("id");
id.setText(add1);
String add2=rs.getString("productName");
productName.setText(add2);
String add3=rs.getString("category");
category.setText(add3);
String add4=rs.getString("price");
price.setText(add4);
String add5=rs.getString("availability");
availability.setText(add5);
String add6=rs.getString("quantity");
quantity.setText(add6);
String add7=rs.getString("description");
description.setText(add7);
} else{

}
JOptionPane.showMessageDialog(null,"Record not found");
}

catch(Exception ex){
JOptionPane.showMessageDialog(null, ex);
}
}
Error.jpg
[Thumbnail for Error.jpg]
 
Maneesh Godbole
Saloon Keeper
Posts: 11341
16
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question will be more suitable for the JDBC forums. Moving...
 
Paul Clapham
Sheriff
Posts: 21581
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're going to need to know what line of code threw that exception. So just looking at the exception's text is not very helpful. You should look at its stack trace. (This applies to all exceptions, not just this particular exception.) The easiest way to do this is



Then the stack trace will show up in your IDE's console (if it's a good IDE). With luck the line numbers in the stack trace will appear as links to the code in the IDE's editor, but at any rate that is what you should look at.
 
chris webster
Bartender
Posts: 2407
33
Linux Oracle Postgres Database Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As a side issue, don't do "SELECT * FROM ...". Always specify the names of the columns so you know what they will be when you execute your code and have to read them out into Java. This will make your code more understandable and help you find errors, and you only need to fetch the data you are actually interested in, instead of the (possibly) hundreds of columns that might be populated for every record in your table.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic