PSQL : ERROR: invalid byte sequence for encoding "UTF8" - java

I am trying to create a logical replication slot via the java PostgreSQL 42.0.0.jre7 API and this is my code :
String url = "jdbc:postgresql://localhost:5432/sampledb?characterEncoding=utf8";
Properties props = new Properties();
PGProperty.USER.set(props, "postgres");
PGProperty.PASSWORD.set(props, "root");
PGProperty.ASSUME_MIN_SERVER_VERSION.set(props, "9.6");
PGProperty.REPLICATION.set(props, "true");
PGProperty.PREFER_QUERY_MODE.set(props, "simple");
DriverManager.registerDriver(new org.postgresql.Driver());
Connection con = DriverManager.getConnection(url, props);
PGConnection replConnection = con.unwrap(PGConnection.class);
replConnection.getReplicationAPI()
.createReplicationSlot()
.logical()
.withSlotName("logical_replication_slot")
.withOutputPlugin("test_decoding")
.make();
but when i run it I get this exception saying that I have an encoding problem.
Caused by: org.postgresql.util.PSQLException: ERROR: invalid byte sequence for encoding "UTF8": 0xe9 0x71 0x75
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2412)[423:org.postgresql.jdbc41:42.0.0.jre7]
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2125)[423:org.postgresql.jdbc41:42.0.0.jre7]
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:297)[423:org.postgresql.jdbc41:42.0.0.jre7]
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:428)[423:org.postgresql.jdbc41:42.0.0.jre7]
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:354)[423:org.postgresql.jdbc41:42.0.0.jre7]
at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:301)[423:org.postgresql.jdbc41:42.0.0.jre7]
at org.postgresql.jdbc.PgStatement.executeCachedSql(PgStatement.java:287)[423:org.postgresql.jdbc41:42.0.0.jre7]
at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:264)[423:org.postgresql.jdbc41:42.0.0.jre7]
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:260)[423:org.postgresql.jdbc41:42.0.0.jre7]
at org.postgresql.replication.fluent.logical.LogicalCreateSlotBuilder.make(LogicalCreateSlotBuilder.java:48)[423:org.postgresql.jdbc41:42.0.0.jre7]
at com.soprahr.hub.replication.postgresql.activator.Activator.start(Activator.java:41)[424:com.soprahr.hub.replication.postgresql:0.0.1.SNAPSHOT]
at org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:697)[org.apache.felix.framework-5.6.1.jar:]
at org.apache.felix.framework.Felix.activateBundle(Felix.java:2226)[org.apache.felix.framework-5.6.1.jar:]
... 16 more
This is my postgres config i have tried sql_ascii, utf8 for client encoding but always the same error :
client_encoding = windows-1251 # actually, defaults to database
# encoding
# These settings are initialized by initdb, but they can be changed.
lc_messages = 'French_France.1252' # locale for system error message
# strings
lc_monetary = 'French_France.1252' # locale for monetary formatting
lc_numeric = 'French_France.1252' # locale for number formatting
lc_time = 'French_France.1252' # locale for time formatting

You just need to change the settings into postgres.conf
lc_messages = 'English_United States.1252'
lc_monetary = 'English_United States.1252'
lc_numeric = 'English_United States.1252'
lc_time = 'English_United States.1252'
default_text_search_config = 'pg_catalog.english'
And don't forget to comment "client_encoding = windows-1251".
This should work!

Related

selenium raises InvalidArgumentException in version 91.0.4472.101 for any given url

Given:
from selenium import webdriver
import os
def setUp_Browser():
if 'nt' in os.name.lower():
# import psutil
# for proc in psutil.process_iter():
# if proc.name() == "chromedriver.exe":
# proc.kill()
time.sleep(1)
caps = webdriver.DesiredCapabilities.CHROME.copy()
caps['goog:loggingPrefs'] = {'performance': 'ALL'}
options = webdriver.ChromeOptions()
options.add_argument("--start-maximized")
options.add_argument('ignore-certificate-errors')
options.add_argument("--incognito")
caps['acceptInsecureCerts'] = True
import pathlib
projectDir = str(pathlib.Path(__file__).parent.absolute()) + "\\Resources\\Drivers\\"
executable_path = os.path.join(projectDir, "chromedriver.exe")
self.browser = webdriver.Chrome(executable_path=executable_path, options=options, desired_capabilities=caps)
time.sleep(3)
self.browser.get(url='www.google.ro')
self.browser.implicitly_wait(15)
time.sleep(4)
I cannot access any given url, it always raises an invalid arg exception after the latest driver update:
File "C:\Users\MunteanuG\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 333, in get
self.execute(Command.GET, {'url': url})
File "C:\Users\MunteanuG\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\MunteanuG\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument
(Session info: chrome=91.0.4472.101)
Some more text so i can post the question...........
Adding http or https, and removing "www." from the url seems to work fime

How to pass java.util.Date to Java library with help of php-java bridge

Im using javabridge to connect php to jasper reports and Im trying to pass two parameters but I get warnings and errors
Warning: Unchecked exception detected: [[o:Response$UndeclaredThrowableErrorMarker]:"FATAL: Undeclared java.lang.RuntimeException detected. java.lang.Exception: CreateInstance failed: new java.util.Date((o:String)[o:String]). Cause: java.lang.IllegalArgumentException VM: 1.7.0_79#http://java.oracle.com/" at: #-10 java.util.Date.parse(Unknown Source) #-9 java.util.Date.<init>(Unknown Source) #-8 sun.reflect.GeneratedConstructorAccessor57.newInstance(Unknown Source) #-7 sun.reflect.DelegatingConstructorAccessor[...]/java/Java.inc(361): java_Arg->getResult(false) #2 http://localhost:8080/JavaBridgeTemplate/java/Java.inc(364): java_Client->getWrappedResult(false) #3 http://localhost:8080/JavaBridgeTemplate/java/Java.inc(536): java_Client->getInternalResult() #4 http://localhost:8080/JavaBridgeTemplate/java/Java.inc(1930): java_Client->createObject('java.util.Date', Array) #5 C:\wamp\www\advanced\backend\javabridge\generate.php(49): Java->Java('java.util.Date', '12/Feb/16') #6 {main}] in http://localhost:8080/JavaBridgeTemplate/java/Java.inc on line 202
Fatal error: Uncaught [[o:Exception]:"java.lang.Exception: Invoke failed: [[c:JasperFillManager]]->fillReport((o:JasperReport)[o:JasperReport], (i:Map)[o:HashMap], (i:Connection)[o:Connection]). Cause: net.sf.jasperreports.engine.JRException: Incompatible php.java.bridge.Response$UndeclaredThrowableErrorMarker value assigned to parameter FInicio in the Reubicados dataset. VM: 1.7.0_79#http://java.oracle.com/" at: #-16 net.sf.jasperreports.engine.fill.JRFillDataset.setParameter(JRFillDataset.java:903) #-15 net.sf.jasperreports.engine.fill.JRFillDataset.setFillParameterValues(JRFillDataset.java:642) #-14 net.sf.jasperreports.engine.fill.JRFillDataset.setParameterValues(JRFillDataset.java:585) #-13 net.sf.jasperreports.engine.fill.JRBaseFiller.setParameters(JRBaseFiller.java:1280) #-12 net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:901) #-11 net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:845) #-10 net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:58) #-9 net.sf.jas in http://localhost:8080/JavaBridgeTemplate/java/Java.inc on line 195
The problem is when it tries to create java.util.Date instance. Here´s php file:
<?php
require_once("http://localhost:8080/JavaBridgeTemplate/java/Java.inc");
try {
$Param1 = date('d/M/y', strtotime($_POST['FInicio']));
$Param2 = date('d/M/y', strtotime($_POST['FFin']));
$jasperxml = new java("net.sf.jasperreports.engine.xml.JRXmlLoader");
$jasperDesign = $jasperxml->load(realpath("Reubicados.jrxml"));
$query = new java("net.sf.jasperreports.engine.design.JRDesignQuery");
$jasperDesign->setQuery($query);
$compileManager = new JavaClass("net.sf.jasperreports.engine.JasperCompileManager");
$report = $compileManager->compileReport($jasperDesign); } catch (JavaException $ex) {
echo $ex; }
$fillManager = new JavaClass("net.sf.jasperreports.engine.JasperFillManager"); //aqui se pasan los parametros (Fecha Inicio y Fecha Fin)
$params = new Java("java.util.HashMap");
$date=new Java('java.util.Date',$Param1);
$date1=new Java('java.util.Date',$Param2);
$params->put("FInicio",$date);
$params->put("FFin",$date1);
$class = new JavaClass("java.lang.Class"); $class->forName("com.mysql.jdbc.Driver"); $driverManager = new JavaClass("java.sql.DriverManager");
//db username and password
$conn = $driverManager->getConnection("jdbc:mysql://localhost/viajestrafico?zeroDateTimeBehavior=convertToNull", "root", "root"); $jasperPrint = $fillManager->fillReport($report, $params, $conn);
$exporter = new java("net.sf.jasperreports.engine.JRExporter");
And sql query in ireports:
SELECT
ayudante_situacion_laboral.`FechaInicio` AS ayudante_situacion_laboral_FechaInicio,
ayudante_situacion_laboral.`FechaFin` AS ayudante_situacion_laboral_FechaFin,
ayudante_situacion_laboral.`Cant_Horas` AS ayudante_situacion_laboral_Cant_Horas,
ayudante_situacion_laboral.`Descripcion` AS ayudante_situacion_laboral_Descripcion,
ayudante.`Registro` AS ayudante_Registro,
ayudante.`Nombre` AS ayudante_Nombre,
situacion_laboral.`Estado` AS situacion_laboral_Estado
FROM
`ayudante` ayudante INNER JOIN `ayudante_situacion_laboral` ayudante_situacion_laboral ON ayudante.`Ayudante_ID` = ayudante_situacion_laboral.`AyudanteAyudante_ID`
INNER JOIN `situacion_laboral` situacion_laboral ON ayudante_situacion_laboral.`Situacion_LaboralSitL_ID` = situacion_laboral.`SitL_ID`
WHERE
situacion_laboral.Estado = 'Reubicado' and $P{FInicio}<= ayudante_situacion_laboral.`FechaInicio` and $P{FFin}>=ayudante_situacion_laboral.`FechaFin`
UNION
SELECT
chofer_situacion_laboral.`FechaInicio` AS chofer_situacion_laboral_FechaInicio,
chofer_situacion_laboral.`FechaFin` AS chofer_situacion_laboral_FechaFin,
chofer_situacion_laboral.`Cant_Horas` AS chofer_situacion_laboral_Cant_Horas,
chofer_situacion_laboral.`Descripcion` AS chofer_situacion_laboral_Descripcion,
chofer.`Registro` AS chofer_Registro,
chofer.`Nombre` AS chofer_Nombre,
situacion_laboral.`Estado` AS situacion_laboral_Estado
FROM
`chofer` chofer INNER JOIN `chofer_situacion_laboral` chofer_situacion_laboral ON chofer.`Chofer_ID` = chofer_situacion_laboral.`ChoferChofer_ID`
INNER JOIN `situacion_laboral` situacion_laboral ON chofer_situacion_laboral.`Situacion_LaboralSitL_ID` = situacion_laboral.`SitL_ID`
WHERE
(situacion_laboral.Estado = 'Reubicado' and $P{FInicio}<= chofer_situacion_laboral.`FechaInicio` and $P{FFin}>=chofer_situacion_laboral.`FechaFin`)
Looking to your error message, the java.util.Date cannot be created with '12/Feb/16':
java_Client->createObject('java.util.Date', Array)
#5 C:\wamp\www\advanced\backend\javabridge\generate.php(49):
Java->Java('java.util.Date', '12/Feb/16') #6 {main}] in
If you want to instanciate a java date object, use the java.util.Date(long date) constructor which accepts a timestamp expressed in milliseconds :
<?php
$startDate = $_POST['FInicio']; // better to filter this :)
$Param1 = strtotime($startDate) * 1000; // to get milliseconds
if ($Param1 == 0) {
throw new Exception("FInicio date parameter could not be parsed");
}
// ...
$javaDate = new Java('java.util.Date',$Param1); // This is a java date
Your $date parameter should now be a valid java.util.Date object.
You can test it :
$simpleDateFormat = new Java("java.text.SimpleDateFormat", 'yyyy-MM-dd');
echo $simpleDateFormat->format($javaDate);
// should print your date in Y-m-d format
Alternatively, you can parse the date in Java through the java.text.SimpleDateFormatter object:
$date = '2016-12-21';
$simpleDateFormat = new Java("java.text.SimpleDateFormat", 'yyyy-MM-dd');
$javaDate = $simpleDateFormat->parse($date); // This is a Java date
Both approaches works...
JasperReport issue with date
Not exactly linked to your question, but if you want to use your Date as a query parameter you should use the java.sql.Date(long date) object instead of java.util.Date... Here's a little dirty snippet to summarize changes:
// php
$sqlDate = new Java('java.sql.Date', strtotime($_POST['FInicio']) * 1000));
$params->put('FInicio', $sqlDate);
// in your report header (.jrxml):
<parameter name="FInicio" class="java.sql.Date">
// in your report query (.jrxml):
$P{FInicio} <= chofer_situacion_laboral.`FechaInicio`
You can also have a look to the soluble-japha javabridge client (refactored Java.inc client), the syntax differs a bit but there's a documentation about dates that might reveal useful.
It was simple, just a problem I had from the beginning in php code.
$query = new java("net.sf.jasperreports.engine.design.JRDesignQuery");
$jasperDesign->setQuery($query);
This code was preventing xrml query from executing, because it was creating a query object empty.

How to fix encoding for JDBC in MATLAB

I'm doing a project with Matlab.
This project is about Thai license plate recognition.
I have a problem with encoding-utf8 (I guess).
The program can recognize and show data in Thai but inserting data in table can't show Thai character. (ex. กข1234 --> ??1234 )
I set collation in utf8_unicode_ci. Did i do anything wrong?
Thank you
Here is some of my code
%# Database
javaaddpath('mysql-connector-java-5.1.6-bin.jar');
host = 'localhost:3306';
user = 'root';
password = '';
dbName = 'smart parking';
%# JDBC parameters
jdbcString = sprintf('jdbc:mysql://%s/%s', host, dbName);
jdbcDriver = 'com.mysql.jdbc.Driver';
%# Create the database connection object
conn = database(dbName, user , password, jdbcDriver, jdbcString);
exec(conn, 'SET character_set_results=UTF-8');
exec(conn, 'SET character_set_client=UTF-8');
exec(conn, 'SET character_set_connection=UTF-8');
exec(conn, 'SET character_set_server=UTF-8');
exec(conn, 'SET NAMES utf8');
% check to make sure that we successfully connected
if isconnection(conn)
SQL_x = ['SELECT * FROM tbl_information WHERE sPlate = ''' R_str ''' AND sOut = 0'];
curs_x = exec(conn, SQL_x);
curs_x = fetch(curs_x);
QUERY_x = curs_x.Data;
if strcmp(QUERY_x, 'No Data') == 1
Plate = R_str;
Sql = ['INSERT INTO tbl_information(sPlate, sTimeIn, sTimeOut, sUse, sPrice, sOut) VALUES(''' Plate ''', ''' datestr(now) ''', '''' , 0, 0, 0)'];
curs = exec(conn, Sql);
end
end
set(handles.text8, 'String', R_str);
drawnow;

MySQL: Intermittant com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

I am getting this exception intermittently and am having a really hard time tracking down how to fix it.
The load on this server is pretty low, and the application is on the same host as the MySQL server connecting via localhost (MySQL 5.6). I have reasonable values for 'connect_timeout' (10), "interactive_timeout' (28800) and 'wait_timeout' (28800) and there is no firewall to cause issues.
Yet every so often this error pops up:
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
Last packet sent to the server was 1 ms ago.
at sun.reflect.GeneratedConstructorAccessor206.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2985)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2871)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3414)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2536)
at com.mysql.jdbc.ConnectionImpl.setAutoCommit(ConnectionImpl.java:4874)
at com.mchange.v2.c3p0.impl.NewProxyConnection.setAutoCommit(NewProxyConnection.java:881)
at org.hibernate.c3p0.internal.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:94)
at org.hibernate.internal.AbstractSessionImpl$NonContextualJdbcConnectionAccess.obtainConnection(AbstractSessionImpl.java:380)
at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:228)
... 76 more
Caused by: java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:2431)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2882)
This is what I have for my Hibernate configuration:
.setProperty("hibernate.hbm2ddl.auto", "validate")
.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL5InnoDBDialect")
.setProperty("hibernate.connection.provider_class", "org.hibernate.connection.C3P0ConnectionProvider")
.setProperty("hibernate.c3p0.idle_test_period", "1000")
.setProperty("hibernate.c3p0.min_size", "1")
.setProperty("hibernate.c3p0.max_size", "20")
.setProperty("hibernate.c3p0.timeout", "1800")
.setProperty("hibernate.c3p0.max_statements", "50")
.setProperty("hibernate.c3p0.debugUnreturnedConnectionStackTraces", "true")
.setProperty("hibernate.c3p0.unreturnedConnectionTimeout", "20")
And this is my MySQL config:
[mysqld]
## General
ignore-db-dir = lost+found
datadir = /var/lib/mysql
socket = /var/lib/mysql/mysql.sock
tmpdir = /var/lib/mysqltmp
## Cache
table-definition-cache = 4096
table-open-cache = 4096
#table-open-cache-instances = 1
#thread-cache-size = 16
#query-cache-size = 32M
#query-cache-type = 1
## Per-thread Buffers
#join-buffer-size = 512K
#read-buffer-size = 512K
#read-rnd-buffer-size = 512K
#sort-buffer-size = 512K
## Temp Tables
#max-heap-table-size = 64M
#tmp-table-size = 32M
## Networking
#interactive-timeout = 3600
max-connections = 400
max-connect-errors = 1000000
max-allowed-packet = 16M
skip-name-resolve
wait-timeout = 600
## MyISAM
key-buffer-size = 32M
#myisam-recover = FORCE,BACKUP
myisam-sort-buffer-size = 128M
## InnoDB
#innodb-buffer-pool-size = 256M
innodb-file-format = Barracuda
#innodb-file-per-table = 1
#innodb-flush-method = O_DIRECT
#innodb-log-file-size = 128M
## Replication and PITR
#binlog-format = ROW
expire-logs-days = 7
#log-bin = /var/log/mysql/bin-log
#log-slave-updates = 1
#max-binlog-size = 128M
#read-only = 1
#relay-log = /var/log/mysql/relay-log
relay-log-space-limit = 16G
server-id = 1
## Logging
#log-output = FILE
#log-slow-admin-statements
#log-slow-slave-statements
#log-warnings = 0
#long-query-time = 2
#slow-query-log = 1
#slow-query-log-file = /var/log/mysql/slow-log
[mysqld_safe]
log-error = /var/log/mysqld.log
#malloc-lib = /usr/lib64/libjemalloc.so.1
open-files-limit = 65535
[mysql]
no-auto-rehash
If load is low you can try to use testConnectionOnCheckout to true
testConnectionOnCheckout Must be set in c3p0.properties, C3P0 default: false
If set to true, an operation will be performed at every connection checkout to verify that the connection is valid.
Actually it's expensive.
A better choice is to verify connections periodically using c3p0.idleConnectionTestPeriod. Try to reduce the value and check how it works

getting exception: The Network Adapter could not establish the connection in simple jdbc program

I was trying to run a simple jdbc code [ using jdk 1.6, oracle 10g] as,
package javaapplication2;
import java.text.*;
import java.sql.*;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.io.BufferedWriter;
/**
* #author animark
*/
public class CallableStatementEx1 {
public CallableStatementEx1(){;}
public static void main(String s[]) throws Exception {
try
{
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
Connection con=null;
String url= "jdbc:oracle:thin:#//localhost:1521:orcl" ;
con = DriverManager.getConnection(url,"scott","password");
String query="update emp set HIREDATE=?,ENAME=? where empno=?";
//Step1: Get PreparedStatement
PreparedStatement ps=con.prepareStatement(query);
//Prepare java.sql.Date object
/*
This logic shows how to convert simple String that is in
dd-MM-yyyy format into Date object
*/
SimpleDateFormat sdf=new SimpleDateFormat("dd-MM-yyyy");
java.util.Date d=sdf.parse("26-12-2001");
java.sql.Date newdate=new java.sql.Date(d.getTime());
//Step2: set parameters
ps.setDate(1,newdate);
ps.setString(2,"animark");
ps.setInt(3,7839);
//Step3: execute the query
int i=ps.executeUpdate();
System.out.println("record updated count: "+i);
con.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}//main
}//class
The code is getting compiled properly. But when I'm trying to run it, i'm getting the following exception..
java.sql.SQLException: Io exception: The Network Adapter could not establish the connection
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:255)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:387)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:414)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:165)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at javaapplication2.CallableStatementEx1.main(CallableStatementEx1.java:19)
I've checked the oracle services and all of them are up and running.
Also, please find the contents of other files as
=================================================================================
tnsnames.ora:
# tnsnames.ora Network Configuration File: C:\oraclexe\app\oracle\product\10.2.0\server\BIN\network\admin\tnsnames.ora
# Generated by Oracle configuration tools.
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
EXTPROC_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
)
(CONNECT_DATA =
(SID = PLSExtProc)
(PRESENTATION = RO)
)
)
====================================================================================
sqlnet.ora
# sqlnet.ora Network Configuration File: C:\oraclexe\app\oracle\product\10.2.0\server\BIN\network\admin\sqlnet.ora
# Generated by Oracle configuration tools.
# This file is actually generated by netca. But if customers choose to
# install "Software Only", this file wont exist and without the native
# authentication, they will not be able to connect to the database on NT.
SQLNET.AUTHENTICATION_SERVICES= (NTS)
NAMES.DIRECTORY_PATH= (TNSNAMES, EZCONNECT)
================================================================================
# listener.ora Network Configuration File: C:\oraclexe\app\oracle\product\10.2.0\server\BIN\network\admin\listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = C:\oraclexe\app\oracle\product\10.2.0\server\BIN)
(PROGRAM = extproc)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
)
)
===============================================================================
I'm being able to connect to the instance "orcl" using credentials "scott/password", but when i'm trying to connect using statement
SQL> connect sys/password#orcl as sysdba
I'm getting the following error..
ORA-12514: TNS:listener does not currently know of service requested in connect
descriptor.
I've also run LSNRCTL for orcl and found
LSNRCTL for 32-bit Windows: Version 10.2.0.1.0 - Production on 22-JUL-2012 13:42:30
Copyright (c) 1991, 2005, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:0 refused:0
LOCAL SERVER
The command completed successfully
Please help me if I'm doing anything wrong here.
Try taking the // out of the connection URL. Instead of
String url= "jdbc:oracle:thin:#//localhost:1521:orcl" ;
try
String url= "jdbc:oracle:thin:#localhost:1521:orcl" ;

Categories

Resources