C:\Tomcat 6.0\webapps\cyberworld\WEB-INF\classes>javac check.java check.java:61: variable Price might not have been initialized Price=Price-int3; ^ check.java:64: variable int1 might not have been initialized "price='" +Price+"' WHERE password="+int1; ^ check.java:104: variable Price1 might not have been initialized Price1=Price1+int3; ^ check.java:107: variable int2 might not have been initialized "price='" +Price1+"' WHERE password="+int2; ^ 4 errors C:\Tomcat 6.0\webapps\cyberworld\WEB-INF\classes>
below is the main code thanks
import java.io.*;
import java.lang.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Check extends HttpServlet{
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException{
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
int int1,int2,int3,Price,Price1,Password;
String str1,str2,str3;
String url = "jdbc:mysql://localhost:3306/test";
String user = "root";
String passer ="root";
try{
Class.forName("com.mysql.jdbc.Driver");
}catch(ClassNotFoundException a){
}
try{
str3 = request.getParameter("str3");
int1=Integer.parseInt(str3);
String run = "SELECT * FROM try " +"WHERE password = " +int1;
System.out.println(run + "SQL string executed");
Connection connection = DriverManager.getConnection(url,user,passer);
Statement stmt = connection.createStatement();
ResultSet result=stmt.executeQuery(run);
while(result.next()){
String name = result.getString(1);
String surname = result.getString(2);
int price = result.getInt(3);
int password = result.getInt(4);
Price=price;
}
connection.close();
}
catch(SQLException a){
}
// price sent
str2 = request.getParameter("str2");
int3=Integer.parseInt(str2);
Price=Price-int3;
//--------------Updating values of the database-------------
String run = "UPDATE try SET " +
"price='" +Price+"' WHERE password="+int1;
try{
Connection connection = DriverManager.getConnection(url,user,passer);
Statement stmt = connection.createStatement();
stmt.executeUpdate(run);
System.out.println("Operation completed...");
connection.close();
}catch(SQLException a){
}
//---Select operation------
try{
Class.forName("com.mysql.jdbc.Driver");
}catch(ClassNotFoundException a){
}
try{
str1 = request.getParameter("str1");
int2=Integer.parseInt(str1);
String run2 = "SELECT * FROM try " +"WHERE password = " +int2;
System.out.println(run2 + "SQL string executed");
Connection connection = DriverManager.getConnection(url,"user","passer");
Statement stmt = connection.createStatement();
ResultSet result=stmt.executeQuery(run2);
while(result.next()){
String name = result.getString(1);
String surname = result.getString(2);
int price = result.getInt(3);
int password = result.getInt(4);
Price1=price;
}
connection.close();
}
catch(SQLException a){
}
Price1=Price1+int3;
//---------Updating the values --
String run1 = "UPDATE try SET " +
"price='" +Price1+"' WHERE password="+int2;
try{
Connection connection = DriverManager.getConnection(url,user,passer);
Statement stmt = connection.createStatement();
stmt.executeUpdate(run1);
System.out.println("Operation completed...");
connection.close();
}catch(SQLException a){
}
}
}


Sign In
Create Account


Back to top









