الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

سؤال بخصوص connection db

بدأه java web developer في 28 أبريل 2011 · 6 رد · 552 مشاهدة · في JavaEE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم انا لدى سؤالين فى مشورعى انا شغالة ب mvc عاملة صفحة html فيها دخول بينات زى اليوزر نيم والباص ورد وهوا كالاتى

<body>
<form action="LoginServelet" method="POST">
username:<input type="text" name="un" >
password:<input type="password" name="pas">


</form>

</body>

وتقوم السيرفلت بفتح اوبجيكت من الكلاس لتتحقق من البيانات هل هوا admin او user

دى الكلاس بتاعتى

public  Connection  c;
public  String name ;
 String password;
 String type="admin";

 public  boolean  IsNameExsist (String un,String pas,String typ) throws SQLException{
   PreparedStatement ps;
   ps=c.prepareStatement("select id from profile  where username=?and password=? and type=?");
 	ps.setString(1,un);
 	ps.setString(2,pas);
 	ps.setString(3,typ);
 ResultSet rs=ps.executeQuery();
 if(rs.next()==true){
   String username=rs.getString(1);
   int password=rs.getInt(2);
   String type=rs.getString(3);
 }
 else{
  return false;
 }

ودى السيرفيلت

    response.setContentType(CONTENT_TYPE);
    PrintWriter out = response.getWriter();
    Mylistener m=new Mylistener();
   Connection k = (Connection)m.c;

    LoginClass l= new  LoginClass();
   String lusername= request.getParameter("un");
   String lpassword=request.getParameter("pas");
String username,password;
   String type="admin";
boolean p;

    try {
      p = l.IsNameExsist(username,password,type);
      if(lusername==username){
        if(lpassword==password){
        if(type.equals("admin")){
          response.sendRedirect("indexadmin.jsp?un="+lusername);
        }
        else{
          response.sendRedirect("indexuser.jsp?un"+lusername);
        }
        }
        else{
          response.sendRedirect("error.jsp?m");
        }
      }
      else{
        response.sendRedirect("error.jsp?p");
      }
    } catch (SQLException e) {
    }
  }                                                   	
}

وانا عاملة ال connection فى listener

والدتا بيز بتاعى اكسيس

السوال الاول ازاى اعمل كونكشن بالدتا بيز الاكسيس من الجى ديفلوبر (انا عمل adminstrative tool--->data source وضيفت ال الديرايفر بس مش عارفة فى البرنامج الجى ديفلوبر اربطو ازاى وخوصا عايز اسم الدتا بيز والباص ورد بتاعتها ؟؟)

السوال التانى البرنامج دا بيطلع ايرورر

Error(20,19): method does not return a value(الميثود بتاعت isnameExist)

Error(40,26): variable username might not have been initialized

Error(40,35): variable password might not have been initialized

يارب يكووون كلامى واضح وقدرت اوصل لحضراتكم سؤااالى وجزاكم الله كل خيرررررررررر

تم تعديل هذه المشاركة بواسطة الشمري في 28 أبريل 2011 في 22:25

#2

أين دالة الاتصال؟

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection(database, "", "");

عفواً أحبتي انقطاعي بسبب الدراسة دعواتكم بالتوفيق..

{ لا ينال العلم مستحٍ ولا مستكبر }

#3
JavaPorgrammer كتب:

أين دالة الاتصال؟

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection(database, "", "");

انا عملتها فى listener

public class Mylistener implements HttpSessionListener {
  private HttpSession session = null;
 public Connection c;
  public void sessionCreated(HttpSessionEvent httpSessionEvent) {
    //session  = event.getSession();
    HttpSession session =httpSessionEvent.getSession();
    try{
      c=getConnection();
    }
    catch(SQLException e){
      System.out.println(e.getMessage());
    }
  }

  public void sessionDestroyed(HttpSessionEvent event) {
    session = event.getSession();
    try{
      c.close();
    }
    catch(SQLException e){
      System.out.println(e.getMessage());
    }
  }

  public static Connection getConnection() throws SQLException {
   String username = "test";
   String password = "test";
    String thinConn = "jdbc:odbc:test:@localhost:1521:ORCL";
    DriverManager.registerDriver(new OracleDriver());
    Connection conn =
      DriverManager.getConnection(thinConn, username, password);
    conn.setAutoCommit(false);
    return conn;
  }

انا كاتبة test اسم الدتا بيز ومش عارفة اكتب اية مكان اليوز نيم والباص ؟

#4
اقتباس

والدتا بيز بتاعى اكسيس

اللي انتي مسويته هو للأوراكل!!

استبدلي مابالدالة getConnection:

بـ :

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

String thinConn = "jdbc:odbc:test";

Connection conn = DriverManager.getConnection(thinConn);

return conn;

طبعا قبلها لازم تعرفي قاعدة البيانات في نظامك على انه Data source ..

مع أعطر التحايا.

عفواً أحبتي انقطاعي بسبب الدراسة دعواتكم بالتوفيق..

{ لا ينال العلم مستحٍ ولا مستكبر }

#5

جزااااااك الله خيرا وجعلة الله فى ميزان حسناتك ويعطيك علم مزيد تنفع بية الناس

معلش لى سؤال بعد اذنك لية الايرور دا بيطلع

Error(20,19): method does not return a value(الميثود بتاعت isnameExist)

Error(40,26): variable username might not have been initialized

Error(40,35): variable password might not have been initialized

والدتا بيز لما اعملها من view --->navigator

اكتب فيها اية ؟

وجزاك الله خيرا

#6
اقتباس

Error(20,19): method does not return a value(الميثود بتاعت isnameExist)

عدلي الدالة :

public  boolean  IsNameExsist (String un,String pas,String typ) throws SQLException{
   PreparedStatement ps;
   ps=c.prepareStatement("select id from profile  where username=?and password=? and type=?");
        ps.setString(1,un);
        ps.setString(2,pas);
        ps.setString(3,typ);
 ResultSet rs=ps.executeQuery();
 if(rs.next()==true){
   String username=rs.getString(1);
   int password=rs.getInt(2);
   String type=rs.getString(3);
 }
 else{
  return false;
 }
return true;
}

اقتباس

Error(40,26): variable username might not have been initialized

Error(40,35): variable password might not have been initialized

اجعلي لهم قيم افتراضية.. وتأكدي من أسماء المتغيرات بالفورم..

بالنسبة لسؤالك عن JDeveloper .. للأسف لم يسبق لي التعامل معه . كان ودي اساعدك

تحية عطرة

تم تعديل هذه المشاركة بواسطة JavaPorgrammer في 29 أبريل 2011 في 01:00

1

عفواً أحبتي انقطاعي بسبب الدراسة دعواتكم بالتوفيق..

{ لا ينال العلم مستحٍ ولا مستكبر }

#7

شكرا جزيلا للك زعلى تعبك وجعلة الله فى ميزان حسناتك ونفعك بعلمك

مواضيع مشابهة