DB-Verbindung (Oracle) funktioniert nicht

  • Themenstarter Themenstarter Louis2
  • Beginndatum Beginndatum
L

Louis2

Hallo,

ich bin kein Java-Experte, deshalb kann es sein, dass mein Quellcode Fehler beinhaltet, würde mich freuen, wenn paar Zeit hätten mal durchzuschauen und zu korrigieren danke!

Bei der Verbindung zu Oracle-DB kommt folgende Fehlermeldung:
Code:
java.sql.SQLException: Protocol violation 
		at oracle.jdbc.dbaccess.DBError.check_error(DBError.java) 
		at oracle.jdbcc7.O3log.receive2nd(O3log.java) 
		at oracle.jdbcc7C7Protocol.logon(TTC7Protocol.java) 
		at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java) 
		at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java) 
		at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java) 
		at java.sql.DriverManager.getConnection(DriverManager.java:512) 
		at java.sql.DriverManager.getConnection(DriverManager.java:171) 
		at examples.Project.MassData.main(MassData.java:18) 
Exception in thread "main"


Mein Quellcode sieht so aus:
Code:
import Prog1Tools.IOTools; 
import java.sql.*; 

public class MassData 
{ 
	public static void main(String[] args) 
	throws ClassNotFoundException, SQLException 
	{ 
		String dbm_user = IOTools.readString("DB-Username:"); 
		String password = IOTools.readString("DB-Password:"); 
		String database_server = IOTools.readString("DB-Server:"); 
		String database_name = IOTools.readString("DB-Name:"); 

		DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver()); 
		String url = "jdbc:oracle:thin:@" + database_server + ":1521:" + database_name; 
		Connection connection = DriverManager.getConnection(url, dbm_user, password); 
		
		boolean question=IOTools.readBoolean("Soll in der DB nur die typical Felder gefüllt werden? (true OR false):"); 
		int numbercustomer=IOTools.readInteger("Anzahl der Firmen die in der DB angelegt werden sollen:"); 
		int numberaddress=IOTools.readInteger("Anzahl der Adressen die in jede Firma angelegt werden sollen:"); 
		int numbercontactp=IOTools.readInteger("Anzahl der Kontaktpersonen die in jeder Adresse angelegt werden sollen:"); 
		int numbercontactn=IOTools.readInteger("Anzahl der Kontaktnummern die in jeder Kontaktperson angelegt werden sollen:"); 
		int numberactivity=IOTools.readInteger("Anzahl der Aktivitäten die angelegt werden sollen:"); 
		int numbertroubleticket=IOTools.readInteger("Anzahl der Problemfälle die angelegt werden sollen:"); 
		
		int c=0; 
		int a=0; 
		int cp=0; 
		int cn=0; 
						
		if (question==true) 
		for (int i=0; i<=numbercustomer; i++) 
		{ 
			Statement company = connection.createStatement(); 
			ResultSet resultcompany = company.executeQuery("INSERT into customer (customerno,companyname,shorttext,customerclass) values (" + (c=c+1) + ",Testcustomer,Testcustomer,K)"); 
			resultcompany.next(); 
			
			for (i=0; i<=numberaddress; i++) 
			{ 
				Statement address= connection.createStatement(); 
				ResultSet resultaddress = address.executeQuery("INSERT into address (addressno,name1,street,streetnumber,zip,city,country,addresstype) values (" + (a=a+1) + ",Testaddress,Teststreet,23,76131,Testcity,D,1)"); 
				resultaddress.next(); 
			
				for (i=0; i<=numbercontactp; i++) 
				{ 
				Statement contactp= connection.createStatement(); 
				ResultSet resultcontactp = contactp.executeQuery("INSERT into contactperson (greetingcode,firstname,lastname) values (MR,Testman,Testman)"); 
				resultcontactp.next(); 
				
					for (i=0; i<=numbercontactn; i++) 
					{ 
					Statement contactn= connection.createStatement(); 
					ResultSet resultcontactn = contactn.executeQuery("INSERT into contactnumber (contactnumbertype,contactnumber) values (1,001122334455)"); 
					resultcontactn.next(); 
					
						for (i=0; i<=numberactivity; i++) 
						{ 
						Statement activity= connection.createStatement(); 
						ResultSet resultactivity = activity.executeQuery("INSERT into activity (subject,state,activitytype,activitypriority) values (Testactivity,NB,ANG,1)"); 
						resultactivity.next(); 
											
							for (i=0; i<=numbertroubleticket; i++) 
							{ 
							Statement troubleticket= connection.createStatement(); 
							ResultSet resulttroubleticket = troubleticket.executeQuery("INSERT into troubleticket (description,troubleticketstate) values (TestSupportCall,AUFG)"); 
							resulttroubleticket.next(); 
							
							troubleticket.close(); 
							resulttroubleticket.close(); 
							} 
						activity.close(); 
						resultactivity.close(); 
						} 
					contactn.close(); 
					resultcontactn.close(); 
					} 
				contactp.close(); 
				resultcontactp.close(); 
				} 
			address.close(); 
			resultaddress.close();	  
			} 
		company.close(); 
		resultcompany.close(); 
		} 
	
		else 
		for (int i=0; i<=numbercustomer; i++) 
		{ 
			Statement company = connection.createStatement(); 
			ResultSet resultcompany = company.executeQuery("INSERT into customer (customerno,companyname,shorttext,searchname,customerclass) values (" + (c=c+1) + ",Testcustomer,Testcustomer,Testcustomer,K)"); 
			resultcompany.next(); 
			
			for (i=0; i<=numberaddress; i++) 
			{ 
				Statement address= connection.createStatement(); 
				ResultSet resultaddress = address.executeQuery("INSERT into address (addressno,name1,name2,name3,street,streetnumber,zip,city,country,region,pobox,zip_pobox,addresstype,language) values (" + (a=a+1) + ",Testaddress,Testaddress,Testaddress,Teststreet,23,76131,Testcity,D,BW,1973,66801,1,de)"); 
				resultaddress.next(); 
			
				for (i=0; i<=numbercontactp; i++) 
				{ 
				Statement contactp= connection.createStatement(); 
				ResultSet resultcontactp = contactp.executeQuery("INSERT into contactperson (greetingcode,firstname,lastname,language,title) values (MR,Testman,Testman,de,Dr.)"); 
				resultcontactp.next(); 
				
					for (i=0; i<=numbercontactn; i++) 
					{ 
					Statement contactn= connection.createStatement(); 
					ResultSet resultcontactn = contactn.executeQuery("INSERT into contactnumber (contactnumbertype,contactnumber) values (1,001122334455)"); 
					resultcontactn.next(); 
					
						for (i=0; i<=numberactivity; i++) 
						{ 
						Statement activity= connection.createStatement(); 
						ResultSet resultactivity = activity.executeQuery("INSERT into activity (subject,state,activitytype,activitypriority,emotion) values (Testactivity,NB,ANG,1,High)"); 
						resultactivity.next(); 
											
							for (i=0; i<=numbertroubleticket; i++) 
							{ 
							Statement troubleticket= connection.createStatement(); 
							ResultSet resulttroubleticket = troubleticket.executeQuery("INSERT into troubleticket (description,troubleticketstate) values (TestSupportCall,AUFG)"); 
							resulttroubleticket.next(); 
							
							troubleticket.close(); 
							resulttroubleticket.close(); 
							} 
						activity.close(); 
						resultactivity.close(); 
						} 
					contactn.close(); 
					resultcontactn.close(); 
					} 
				contactp.close(); 
				resultcontactp.close(); 
				} 
			address.close(); 
			resultaddress.close();	  
			} 
		company.close(); 
		resultcompany.close(); 
		} 
		connection.close();		
	} 
}
Bin für jede Hilfe dankbar!

Gruß
 
Hallo!

Wahrscheinlich wird deine Oracle JDBC URL falsch gebaut...
dieso sollte so aussehen:
jdbc:oracle:thin:@//myserver.com/customer_db

Gruß Tom
 
Zurück