PDA

View Full Version : کد زیر در نتبینز



arezo1174
یک شنبه 20 فروردین 1391, 17:50 عصر
سلام اساتید امکان داره یه نگاه به این کد بندازید ببینید اشکالش کجاست؟؟

public class Person {
private int id;
private String name;
private String family;

public Person(){

}

public Person(int id, String name, String family){
this.id=id;
this.name=name;
this.family=family;
}

public Person(String name,String family){
this.name=name;
this.family=family;
}

public int getId(){
return id;
}
public void setID(int id){
this.id=id;
}

public String getName(){
return name;
}
public void setName(String name){
this.name=name;
}

public String getfamiy(){
return family;
}
public void setfamily(String family){
this.family=family;
}
}



اینم کلاس ...

import java.sql.*;
import java.util.Vector;
public class DBHandler {

private static Connection cn;
private static Statement st;

//open DB connection
private static void open() throws Exception{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
cn=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;" +

"databaseName=student;user=sa;password=12345;");
st=cn.createStatement();
}

public static void insertPerson(Person person) throws Exception{
open();
String query="INSERT INTO PERSON "+
"(NAME,FAMILY) VALUES ('"+
person.getName()+"','"+
person.getfamiy()+"')";
st.executeUpdate(query);
Close();
}
public static void remove(Person person) throws Exception{
open();
String query="DELETE PERSON WHERE ID= "+
person.getId();
st.executeUpdate(query);
Close();
}

public static void updatePerson(Person person) throws Exception{
open();
String query="UPDATE PERSON SET NAME='"+
person.getName()+
"',FAMILY='"+
person.getfamiy()+
"'WHERE ID="+
person.getId();
st.executeUpdate(query);
Close();
}
public static Person[] getAllPersons() throws Exception{
Vector v=new Vector();
open();
String query="SELECT *FROM PERSON";
ResultSet result=st.executeQuery(query);
while(result.next()){
int id=result.getInt("ID");
String name=result.getString("NMAME");
String family=result.getString("FAMILY");
Person person=new Person(id,name,family);
v.addElement(person);
}
Close();
return(Person[]) v.toArray(new Person[0]);
}

public static void Close() throws Exception{
st.close();
cn.close();
}

}


و اینم main

public class Main {

/**
* @param args the command line arguments
*/
public static void main(String[] args) throws Exception {
// TODO code application logic here
Person p=new Person("Ali","mohammady");
DBHandler.insertPerson(p);

}

}

arezo1174
یک شنبه 20 فروردین 1391, 17:53 عصر
میدونم برنامه اش ساده اس ولی خوب من گیر کردم توش:گریه::گریه::گریه:

spiderman200700
یک شنبه 20 فروردین 1391, 20:15 عصر
مشکل چیه؟
اجرا نمیشه یا خطای خاصی میده؟
لطفا سوالتونو کامل بپرسید

spiderman200700
یک شنبه 20 فروردین 1391, 20:39 عصر
اینو امتحان کن اگه بازم نشد خطایی که توی خروجی میده رو اینجا بذار تا کمکت کنیم.

import java.sql.*;
import java.util.Vector;

public class DBHandler {

private static Connection cn;
private static Statement st;

//open DB connection
private static void open() throws Exception {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
cn = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;"
+ "databaseName=student;user=sa;password=12345;");
st = cn.createStatement();
}

public static void insertPerson(Person person) throws Exception {
open();
String query = "INSERT INTO PERSON "
+ "(NAME,FAMILY) VALUES ('"
+ person.getName() + "','"
+ person.getfamiy() + "')";
st.executeUpdate(query);
Close();
}

public static void remove(Person person) throws Exception {
open();
String query = "DELETE PERSON WHERE ID= "
+ person.getId();
st.executeUpdate(query);
Close();
}

public static void updatePerson(Person person) throws Exception {
open();
String query = "UPDATE PERSON SET NAME='"
+ person.getName()
+ "',FAMILY='"
+ person.getfamiy()
+ "'WHERE ID="
+ person.getId();
st.executeUpdate(query);
Close();
}

public static Person[] getAllPersons() throws Exception {
Vector v = new Vector();
open();
String query = "SELECT *FROM PERSON";
ResultSet result = st.executeQuery(query);
while (result.next()) {
int id = result.getInt("ID");
String name = result.getString("NMAME");
String family = result.getString("FAMILY");
Person person = new Person(id, name, family);
v.addElement(person);
}
Close();
return (Person[]) v.toArray(new Person[0]);
}

public static void Close() throws Exception {
st.close();
cn.close();
}

public static void main(String[] args) throws Exception {
// TODO code application logic here
Person p = new Person("Ali", "mohammady");
DBHandler.insertPerson(p);

}
}

class Person {

private int id;
private String name;
private String family;

public Person() {
}

public Person(int id, String name, String family) {
this.id = id;
this.name = name;
this.family = family;
}

public Person(String name, String family) {
this.name = name;
this.family = family;
}

public int getId() {
return id;
}

public void setID(int id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getfamiy() {
return family;
}

public void setfamily(String family) {
this.family = family;
}
}

arezo1174
دوشنبه 21 فروردین 1391, 22:03 عصر
مرسی از جوابتون

Ma_Y_R
سه شنبه 29 فروردین 1391, 19:31 عصر
public void compare()
}
(++first: for(int i=0;i<Array2.length;i
}
(++ for(int j=0;j<Array2[i].length;j
}
( [if(Array2[i][j]>Array[i][j
}
: ("System.out.println("is false
; break firs
{
{
{
("System.out.println("is true
{



سلام دوستان.تو این برنامه میخوام در صورت درستی شرط پیغام چاپ بشه و کل متد تموم بشه اما پیغام true هم چاپ میشه.لطفا کمک کنید.:ناراحت::ناراحت::ناراحت :