I created a program wherein the selected database will open in the jtable and it will print the report and can save it as .pdf .docx and so on. The sql statement I used is a fixed one or hard coded meaning when I run the program it will automatically connects to the database I wrote in the system. It needs to be changeable where in the user can choose what database to open and will create a report review.
This is the default connection statement right? wherein the connection is fixed and cannot be change?
Connection con = DriverManager.getConnection(
"jdbc:oracle:thin:#dbaprod1:1544:SHR1_PRD", username, passwd);
First Thing,
If you really want user to choose which database to open then you have to read the database name , username , password and even You have to get the ip address of the computer containing the database.
//The url will change according to the user's input
String URL = "jdbc:oracle:thin:#amrood:1521:EMP";
String USER = "username";
String PASS = "password"
Connection conn = DriverManager.getConnection(URL, USER, PASS);
Second Thing,
Even after you get the ip address of the computer containing the database you can only access the databse if the user has permited remote sharing or control to the file.
ThankYou. I hope this was helpful
When tried to ping JDBC Connection Pool got error that Ping Connection Pool failed:
Connection could not be allocated because: Connection authentication failure occurred. Reason: Userid or password invalid. Userid and password are both set to APP.
To authenticate to the database, you must supply credentials that match an existing user in the database. So, first create the username and password in the database and then use the exact same values when you configure your connections.
The username and password can be pretty much any values. The important thing is that the values you specify when you connect to the database must exactly match the values that are set in the database.
To establish a username and password in the database use a command like:
CREATE USER 'username'#'localhost' IDENTIFIED BY 'password';
You will replace 'username' with the desired username (in this case 'APP') and replace 'password' with the desired password (in this case 'APP').
I have been trying to connect to Teradata
Class.forName("com.teradata.jdbc.TeraDriver");
String connectionString = "jdbc:teradata://xxx.xxxxxx.com/database=xxxxxx, tmode=ANSI, charset=UTF8";
String user = "Rocket512";
String password = "aui8mn5";
Connection conn = DriverManager.getConnection(connectionString, user, password);
Got the following
Exception in thread "main" com.teradata.jdbc.jdbc_4.util.JDBCException: [Teradata Database]
[TeraJDBC 14.10.00.17] [Error 8017] [SQLState 28000] The UserId, Password or Account is invalid.
at com.teradata.jdbc.jdbc_4.util.ErrorFactory.makeDatabaseSQLException(ErrorFactory.java:300)
at com.teradata.jdbc.jdbc.GenericLogonController.run(GenericLogonController.java:666)
at com.teradata.jdbc.jdbc_4.TDSession.<init>(TDSession.java:216)
I know that the host is specified correctly since i did not get UnknownHost Exception.
Also I have double checked my userid and password are correct.
I ran query suggested by #beni23 (thank you)
select *
from dbc.logonoff
where logdate >= date '2013-10-31'
Here is the result that I got
What is Bad Password? I used SQL Assistant with this very password and it works great. Why cannot i connect with Java?
LDAP Authentication failures will not be captured in DBC.LogOnOff as a Bad Password event because the authentication doesn't take place on the database.
Typically the error message you are receiving, The UserId, Password or Account is invalid., is indicative of the user account being locked on the database.
SELECT U.UserName
, U.ProfileName
, U.DefaultAccount
, COALESCE(P.MAXLOGONATTEMPTS, S.MAXLOGONATTEMPTS) AS MaxLogonAttempts_
, U.LockedCount
, U.LockedDate
FROM dbc.UsersV U
LEFT JOIN
dbc.ProfileInfoV P
ON P.ProfileName = U.ProfileName
CROSS JOIN
dbc.SecurityDefaults S
WHERE UserName = 'Rocket512';
If LockedCount is not 0 than a failed logon attempt has occurred since the last successful logon to the database.
If LockedDate is not NULL it represents the date which the account was last locked.
MaxLogonAttempts_ will tell you how many times you can attempt to logon using database authentication (TD2) before the account is locked.
A couple of things I would suggest:
Remove whitespace between the parameters of connectString
Put the User and Password parameters in the connectString
Using original code above modify the connectString to add: ,ACCOUNT=$AMRWRW&DrT&r which should match what is returned by the query in my response above (I have added DefaultAccount).
EDIT: 11/12/13
May I suggest you download Teradata Studio Express and attempt to make a connection to the same Teradata system using JDBC much like you are here in your code. This may help shed light on the parameters you need to specify in your connection string in order to make the connection successful. You should be able to setup your connection parameters in Teradata Studio Express the same as you have here in your code and see if it works.
Using LDAP as the logon mechanism for a user that has not been granted the explicit right to logon with a NULL password has resulted in the error message `The UserId, Password or Account is invalid.'. I received this the other day using a privileged account without changing my logon mechanism from LDAP to TD2.
What does the following SQL return?
SELECT *
FROM DBC.LogonRulesV
WHERE UserName = 'Rocket512';
It may not return anything, which is okay. This simply means you ability to logon with that userid from any host on the system has not been explicitly granted or revoked.
EDIT: 05/22/18
The “Bad Password” event for an externally authenticated user may will appear in the event log when the provided password and the what is stored on the directory server do not match. In certain scenarios you can verify this by using ldapsearch from the PDN to submit an inquiry directly to the LDAP directory. You can find more details about using this command in the Security Administration manual. I’ve discovered this trying to triage a problem with a subset of user accounts that fail to authenticate to the directory. I felt it would be appropriate to update this answer with more details as my lead in statement at the top is not 100% accurate.
The following might not give you a solution, but might point you in the right direction. I think you'll want to check the dbc.logonoff table in teradata through a console to make sure that your user is not locked or get an idea whether your driver is hitting teradata.
select *
from dbc.logonoff
where logdate >= date '2013-10-31'
Reading this article Troubleshooting Security: The UserId, Password or Account is invalid. we can see the typical reason of this error.
Cause: LOGMECH=LDAP is specified, and the username/password credentials
are redundantly provided in the both LOGDATA and as separate
connection parameters.
Solution: Identify LDAP users via LOGDATA, or
via separate username/password parameters, but not both
simultaneously.
So, you should check this case. May be you can get connection without user/password
Perhaps you might have more luck with:
String driver = "com.teradata.jdbc.TeraDriver";
String conUrl="jdbc:teradata://xxx.xxxxxx.com/database=xxxxxx,USER=Rocket512,PASSWORD=aui8mn5,tmode=ANSI,charset=UTF8";
Class.forName(driver);
Connection dbConn = DriverManager.getConnection(conUrl);
If that doesn't work make sure to use the latest jdbc driver.
I had similar error and followed all the suggestions given in here. My account was not locked and I was able to connect to the DB with the same username and password, via SQL assistance editor.
The solution worked for me was adding following line in the connection string: LOGMECH=LDAP.
You need to know the logon mechanism for your Teradata, or you can reach out to your DBA team, as I did. So your connection string will look something like this:
String connurl="jdbc:teradata://xx/database=xx,USER=xx,PASSWORD=xx,tmode=ANSI,charset=UTF8,LOGMECH=LDAP";
I'm working on a front end for a database I have set up and I was wondering if I just use this code will my password and username show up in plain text if some one is sniffing?
String url = "jdbc:mysql://" + address + "/table";
String user = user_Name;
String password = complete_Password;
Connection conn = null;
try {
conn = DriverManager.getConnection(url, user, password);
return conn;
} catch (SQLException ex) {
System.out.println(ex);
}
That depends on how the JDBC driver is implemented, the MySQL JDBC driver will not transmit your password in clear text. You can see this happening at the MysqlIO class (look for the changeUser method).
You can also see the various types of authentication MySQL offers (including the very unsafe clear text passwords over the wire) at it's client-server protocol documentation.
I seriously doubt any vendor produced database driver out there will send your password data as clear text over the wire. At least I know the MySQL and PosgreSQL JDBC drivers will not do this. PostgreSQL, for instance, will generate a hash of your password and send it.
JDBC is merely an API. every JDBC driver implementation is different, so this would be up to the particular driver that you were using.
I am trying jdbc connection with mysql but getting SQLException.
My code is:--
public void createConn() throws MysqlException {
try {
String url ="jdbc:mysql://172.168.1.73:3306/mysql";
Connection con =DriverManager.getConnection(url,"root", "");
System.out.println("URL: " + url);
System.out.println("Connection: " + con);
}
i am getting following exception...
java.sql.SQLException: Access denied for user 'root'#'192.168.1.187'
(using password: NO)
I am trying to connect to 172.168.1.73 but it is trying to coonect to 192.168.1.187...
root user doesnt have any password.
Please tell me how can i solve this issue.
Check whether root user can access the machine with IP 192.168.1.187
It is not trying to connect to 192.168.1.187.
'root'#'192.168.1.187' in the exception means a user with user name "root" in the machine with IP '192.168.1.187' trying to access the database server. Therefore 192.168.1.187 is the client IP.
Database servers restricts the access based on user and the IP of the machine user use to connect. Therefore if you want to connect to the database server from a IP '192.168.1.187', you should grant permission to access the user to access from that specific IP.
Check MySQL GRANT for more details.
To be more secure, you need to assign the root password and try it again. The page below contains Java code to connect to mysql database:
http://www.worldbestlearningcenter.com/index_files/java_database_connect_mysql.htm