Kodları lütfen aşağıdaki butonları kullanarak renklendirin. Örnek: <php> echo "Selam Dünya"; </php>
Yardım
karakter kaldı

arkadaşlar hiç hata almıyorum fakat eclipse konsounada system.in verisi yazamıyorum

package veri;


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Scanner;

public class veriler {

	public String data = "jdbc:mysql://localhost:3306/veriler";	
	public String user = "root";
	public String pass = "";
	public Connection conn;
	
	public veriler(){
		
		try{
			
			
			
			conn = DriverManager.getConnection(data,user,pass);
			
			if(conn != null){
				
				System.out.println("CONNECTED");
				
			}else{
				
				System.out.println("DISCONNECTED");
				
			}
			
			
			
		}catch(Exception ex){
			
			System.out.println("ERROR :  " + ex);
			
		}
		
		
		
		
		
	}	
	
	
	
	public void ekle(){
		
		
		
		
		Scanner al = new Scanner(System.in);
		
		System.out.println("Please enter name");
		
		String name = al.next();
		
		System.out.println("Please enter surname");
		
		String surname = al.next();
		
		al.close();
		
		String sql = "INSERT INTO users (name,surname) VALUES (?,?)";
		
		try{
		
		PreparedStatement ekle = conn.prepareStatement(sql);
		
		ekle.setString(1, name.toString());
		
		ekle.setString(2, surname.toString());
		
		int r = ekle.executeUpdate();
		
		if(r > 0){
			
			System.out.println("INSERTED");
			
			
		}else{
			
			System.out.println("FAILED");
			
		}
		
		}catch(Exception ex){
			
			System.out.println("ERROR : " + ex);
			
		}
		
		
		
	}
	
	
	public void guncelle(){
		
		
		
		
		Scanner al = new Scanner(System.in);
		
		System.out.println("Please enter name");
		
		String name = al.next();
		
		System.out.println("Please enter surname");
		
		String surname = al.next();
		
		System.out.println("Please enter where name");

		String where = al.next();
		
		al.close();
		
		String sql = "UPDATE users SET name=?,surname=?  WHERE (name=?)";
		
		try{
		
		PreparedStatement guncelle = conn.prepareStatement(sql);
		
		guncelle.setString(1, name.toString());
		
		guncelle.setString(2, surname.toString());
		
		guncelle.setString(3, where.toString());
		
		int r = guncelle.executeUpdate();
		
		if(r > 0){
			
			System.out.println("UPDATED");
			
			
		}else{
			
			System.out.println("FAILED");
			
		}
		
		}catch(Exception ex){
			
			System.out.println("ERROR : " + ex);
			
		}
		
		
		
	}
	
	
	public void sil(){
		
		
		
		
		Scanner al = new Scanner(System.in);

		System.out.println("Please enter name");	
			
		String where = al.next();
		
		al.close();
		
		String sql = "DELETE FROM users WHERE (name=?)";
		
		try{
		
		PreparedStatement sil = conn.prepareStatement(sql);
		
		
		sil.setString(1, where.toString());
		
		int r = sil.executeUpdate();
		
		if(r > 0){
			
			System.out.println("UPDATED");
			
			
		}else{
			
			System.out.println("FAILED");
			
		}
		
		}catch(Exception ex){
			
			System.out.println("ERROR : " + ex);
			
		}
		
		
		
	}
	
	
	
	
	public void listing(){
		
		
		
		
		String sql = "SELECT * FROM users";
		
	
		try {
			
			java.sql.Statement listele = conn.createStatement();
			ResultSet rs = listele.executeQuery(sql.toString());
			
			int count=0;
			
			while(rs.next()){
				
				String name = rs.getString(1);
				String surname = rs.getString(2);
				String output = "%d - %s - %s";
				System.out.println(String.format(output, ++count,name,surname));
				
			}
			
			
		} catch (Exception e) {
			
			System.out.println("ERRROR : " + e);
			
		}
		
		
		
		
		
	}
	
	public static void main(String args[]){
		
		veriler veri = new veriler();
		
		System.out.println("Please enter one->(listele,ekle,guncelle,sil)");
		
		Scanner al = new Scanner(System.in);
		
		al.close();
		
		if(al.equals("listele")){
			
			veri.listing();
			
		}else if(al.equals("ekle")){
		
				veri.ekle();
		
		}else if(al.equals("guncelle")){
			
			veri.guncelle();
	
		}else if(al.equals("sil")){
			
			veri.sil();
	
		}
	}
	
	
}

+0
-0
Cevaba KatılıyorumKatılmıyorum
Cevap Yaz Yorum Yaz Arşivime Ekle Takip Et

Doğru Cevap

  • max1299 adlı üyenin fotoğrafı
    3 yıl önce yazılmış
    28 cevap - 30 soru
       System.out.println("Please enter one->(listele,ekle,guncelle,sil)"); //burada tıkanıyor veri giremiyorum
    


    yardımlarınız için teşekkürler
    • max1299 adlı üyenin fotoğrafı max1299
      package veri;
      
      
      import java.sql.Connection;
      import java.sql.DriverManager;
      import java.sql.PreparedStatement;
      import java.sql.ResultSet;
      import java.util.*;
      import java.sql.Statement;
      
      public class veriler {
      
      	public String data = "jdbc:mysql://localhost:3306/veriler";	
      	public String user = "root";
      	public String pass = "";
      	public Connection conn;
      	
      	public veriler(){
      		
      		try{
      			
      			
      			
      			conn = DriverManager.getConnection(data,user,pass);
      			
      			if(conn != null){
      				
      				System.out.println("CONNECTED");
      				
      			}else{
      				
      				System.out.println("DISCONNECTED");
      				
      			}
      			
      			
      			
      		}catch(Exception ex){
      			
      			System.out.println("ERROR :  " + ex);
      			
      		}
      		
      		
      		
      		
      		
      	}	
      	
      	
      	
      	public void ekle(){
      		
      		
      		
      
      		System.out.println("Please enter name");
      		Scanner ale = new Scanner(System.in);
      		String name = ale.next();
      		System.out.println("Please enter surname");
      		Scanner ale1 = new Scanner(System.in);
      		String surname = ale1.next();
      		
      		try{
      			
      		String sql = "INSERT INTO users (name,surname) VALUES (?,?)";
      		
      		PreparedStatement ekle = conn.prepareStatement(sql);
      		
      		ekle.setString(1, name.toString());
      		
      		ekle.setString(2, surname.toString());
      		
      		int r = ekle.executeUpdate();
      		
      		if(r > 0){
      			
      			System.out.println("INSERTED");
      			
      			
      		}else{
      			
      			System.out.println("FAILED");
      			
      		}
      		
      		}catch(Exception ex){
      			
      			System.out.println("ERROR : " + ex);
      			
      		}
      		
      		
      		
      	}
      	
      	
      	public void guncelle(){
      		
      		
      		
      		System.out.println("Please enter name");
      		Scanner alg = new Scanner(System.in);
      		String name = alg.next();
      		System.out.println("Please enter surname");
      		Scanner alg1 = new Scanner(System.in);
      		String surname = alg1.next();
      		System.out.println("Please enter where name");
      		Scanner alg2 = new Scanner(System.in);
      		String where = alg2.next();
      		
      		try{
      		
      		String sql = "UPDATE users SET name=?,surname=?  WHERE (name=?)";
      		
      		PreparedStatement guncelle = conn.prepareStatement(sql);
      		
      		guncelle.setString(1, name.toString());
      		
      		guncelle.setString(2, surname.toString());
      		
      		guncelle.setString(3, where.toString());
      		
      		int r = guncelle.executeUpdate();
      		
      		if(r > 0){
      			
      			System.out.println("UPDATED");
      			
      			
      		}else{
      			
      			System.out.println("FAILED");
      			
      		}
      		
      		}catch(Exception ex){
      			
      			System.out.println("ERROR : " + ex);
      			
      		}
      		
      		
      		
      	}
      	
      	
      	public void sil(){
      		
      		
      		
      		System.out.println("Please enter name");
      		Scanner als = new Scanner(System.in);
      		String where = als.next();
      		
      		try{
      		
      		String sql = "DELETE FROM users WHERE (name=?)";
      		
      		PreparedStatement sil = conn.prepareStatement(sql);
      		
      		sil.setString(1, where.toString());
      		
      		int r = sil.executeUpdate();
      		
      		if(r > 0){
      			
      			System.out.println("DELETED");
      			
      			
      		}else{
      			
      			System.out.println("FAILED");
      			
      		}
      		
      		}catch(Exception ex){
      			
      			System.out.println("ERROR : " + ex);
      			
      		}
      		
      		
      		
      	}
      	
      	
      	
      	
      	public void listing(){
      		
      		try {
      			
      
      			String sql = "SELECT * FROM users";
      			Statement listele = conn.createStatement();
      			ResultSet rs = listele.executeQuery(sql.toString());
      			
      			int count=0;
      			
      			while(rs.next()){
      				int id = rs.getInt("id");
      				String name = rs.getString("name");
      				String surname = rs.getString("surname");
      				String output = "%d - %d - %s - %s";
      				System.out.println(String.format(output, ++count,id,name,surname));
      				
      			}
      			
      			
      		} catch (Exception e) {
      			
      			System.out.println("ERRROR : " + e);
      			
      		}
      		
      		
      		
      		
      		
      	}
      	
      	
      	public static void main(String args[]){
      		
      		veriler veri = new veriler();
      		
      
      		while(true){
      		
      		System.out.println("Please enter one->(listele,ekle,guncelle,sil)");
      		
      		Scanner al = new Scanner(System.in);
      		
      		String algetir = al.next();
      		
      		switch(algetir){
      		
      		case "listele" : veri.listing(); break;
      		case "guncelle" : veri.guncelle(); break;
      		case "ekle" : veri.ekle(); break;
      		case "sil" : veri.sil(); break;
      		
      		}
      		
      		}
      	}
      	
      	
      }
      
      


      BUŞEKİLDE SORUNU ÇÖZDÜM
      3 yıl önce yazılmış
    • max1299 adlı üyenin fotoğrafı max1299
      ASLINDA BU SCANNER NESNESİ AÇILIP BİR DEĞİŞKENE ATANIP HER AÇILAN SCANNER DEĞİŞKENİNİNDE FARKLI İSMİ OLMALAI
      3 yıl önce yazılmış

Cevaplar

Hiç cevap bulunamadı.