Originally posted by Lex Wouda:
Hi,
String product = "";
int aantal = 0;
double price = 0;
String id = "3";
double GrandTotal =0;
String dbuser = "user";
String dbpassword = "password";
String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
String url = "jdbc dbc:getsildb";
try{
Driver drv = (Driver) Class.forName(driver).newInstance();
Properties p = new Properties();
p.put("user", dbuser);
p.put("password", dbpassword);
Connection con = DriverManager.getConnection(url,dbuser,dbpassword);
Statement stmt = con.createStatement();
String query = "SELECT id,product,prijs,aantal FROM product ,buy WHERE kid="+id+" AND pid=productid ";
ResultSet rs = stmt.executeQuery(query);
while (rs.next())
{
product = rs.getString("product");
price = rs.getDouble("prijs");
aantal = rs.getInt("aantal");
double total = aantal*price;
GrandTotal = GrandTotal + total;
System.out.println(" id = "+Integer.toString(rs.getInt("id")));
}
//close statment and connection
stmt.close();
con.close();
}
catch(Exception se) {System.out.println(se);}
}
Lex
<%<br /> String product = "";<br /> int aantal = 0;<br /> double price = 0;<br /> String id = "3";<br /> double GrandTotal =0;<br /> String dbuser = "user";<br /> String dbpassword = "password";<br /> String driver = "sun.jdbc.odbc.JdbcOdbcDriver";<br /> String url = "jdbc dbc:getsildb";<br /> try{<br /> <br /> Driver drv = (Driver) Class.forName(driver).newInstance();<br /> <br /> Properties p = new Properties();<br /> p.put("user", dbuser);<br /> p.put("password", dbpassword);<br /> Connection con = DriverManager.getConnection(url,dbuser,dbpassword);<br /> <br /> Statement stmt = con.createStatement();<br /> String query = "SELECT id,product,prijs,aantal FROM product ,buy WHERE kid="+id+" AND pid=productid ";<br /> <br /> ResultSet rs = stmt.executeQuery(query);<br /> while (rs.next())<br /> {<br /> product = rs.getString("product");<br /> price = rs.getDouble("prijs");<br /> aantal = rs.getInt("aantal");<br /> double total = aantal*price;<br /> GrandTotal = GrandTotal + total;<br /> %>
<%=rs.getString("id")%>
<%<br /> <br /> }<br /> //close statment and connection<br /> stmt.close();<br /> con.close();<br /> }<br /> catch(Exception se) {System.out.println(se);}<br /> }<br /> %>
Lex
Conversion occurrs automatically.Why does it work when I call getString on an number field?
Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog