I'm trying to get all the database on my server. But specifying my server name in getDbDirectory() parameter as NALLN304/40/LLN/IBM gives me a error.
Directory NALLN304/40/LLN/IBM!! does not exist
it always add two exclamation mark at the end. I tried also as server name and mail file adding .nsf format at the end of mail file. NALLN304/40/LLN/IBM!!data0\126\1000031540.nsf also gives me the same error.
Snipper code below:
Session session = null;
Database db = null;
DbDirectory dir = null;
try
{
NotesThread.sinitThread();
session = NotesFactory.createSession();
System.out.println("User = " + session.getUserName());
dir = session.getDbDirectory("NALLN304/40/LLN/IBM");
System.out.println(dir.getName());
db = dir.getFirstDatabase(DbDirectory.DATABASE);
do
{
System.out.println("Title: " +db.getTitle());
}
while(dir.getNextDatabase() != null);
}
catch(NotesException ex)
{
ex.printStackTrace();
}
The error always points out to the db = dir.getFirstDatabase(DbDirectory.DATABASE); because dir.getFirstDatabase(DbDirectory.DATABASE) expects .nsf file even I specify the file format. Any reasons why I got this error?
Your problem is that your ID is not authenticating with the server. You need to take the output from this line:
System.out.println("User = " + session.getUserName());
And take it to your server administrators, ask why it is not being allowed to access the server, and ask them to assist you either by granting the necessary permissions or by giving you another ID that you can use.
Check the logs for server connection errors. Even if the server has to connect to itself. Faced the same problem. The server gave an error because it did not find a route for the connection. Added a new connection for the server to itself and everything was fixed
Related
I'm working on a project and I have put my database folder in project folder. How can I make a database connection to any directory rather than just default MySQL dir in Java?
String MySQLURL = "jdbc:mysql://localhost:3306/C:\\Program Files\\SnakeGame";
String UserName = "root";
String Password = "admin";
Connection con = null;
try {
con = DriverManager.getConnection(MySQLURL,UserName,Password);
if (con != null) {
System.out.println("Database connection is successful !!!!");
}
} catch (Exception e) {
e.printStackTrace();
}
When doing this, I get this error:
java.sql.SQLSyntaxErrorException: Unknown database 'c:\program files\snakegame'
Your connection URL is wrong
String MySQLURL = "jdbc:mysql://localhost:3306/C:\\Program Files\\SnakeGame";
I am not sure why your MySQLURL contains C:\Program Files\SnakeGame
The connection URL for the mysql database is
jdbc:mysql://localhost:3306/[DatabaseName]
Where jdbc is the API, mysql is the database, localhost is the server name on which mysql is running (we may also use the server's IP address here), 3306 is the port number, and [DatabaseName] is the name of the database created on the MySQL server.
Replace the [DatabaseName] name accordingly after creating the database in MySQL server
Combining localhost:3306/ with C:\\Program Files\\SnakeGame makes little sense for any database - either you're trying to connect to a file-based database (in which case the localhost... part makes no sense) or you're working with a server-based one (in which case the C:\... part makes no sense.
Also, this connection string would make little sense for a file-based database either because you didn't specify a specific file, just a path.
Incidentally, MySQL is server-based, not file-based. It's expecting a database name after the localhost:3306/ part, not a path (hence the error). The physical location of the actual database program is an installation/configuration issue - it has nothing to do with how you actually connect to the database server once it's already running.
Think about it this way: when you call an external database, web service, or web site, do you need to know which physical folder it's deployed to? Obviously not. The physical folders involved are completely irrelevant when calling MySQL or another database like this.
One of the comments pointed this out, but did you intend to use SQlite or some other file-based database here instead?
I'm having this problem when trying to connect to my database. Change the value of the variable but still this error persists
Value mysql
##max_allowed_packet
16777216
Java Code
Properties connProps = new Properties();
connProps.put("user", Config.DB_USER);
connProps.put("password", Config.DB_PASS);
this._conn = DriverManager.getConnection("jdbc:" + Config.DB_DBMS + "://" + Config.DB_HOST + ":"
+ Config.DB_PORT + "/" + Config.DB_NAME, connProps);
Error :
com.mysql.jdbc.PacketTooBigException: Packet for query is too large (4739923 > 1048576). You can change this value on the server by setting the max_allowed_packet' variable.
Modify the my.cnf file on my server
The jdbc client, also has a "maxAllowedPacket" setting.
You may set your jdbc url like:
jdbc:mysql://192.168.15.1/dbname?useUnicode=true&characterEncoding=UTF-8&maxAllowedPacket=16777216
Had the same error, trying to connect to a MySQL database using DataGrip 2016.1 (from JetBrains).
Troubleshooting further, I've realised that my records entry were wrong; the database password was not correct.
Upon rectification using the correct database password, I no longer encountered the error and was able to connect successfully.
In a managed bean that resides in a Database on the server Development I have this code:
s = ExtLibUtil.getCurrentSession();
theMap.put("Server Name", s.getServerName());
when I look at theMap after this has run I see Server Name and the value is blank. After this I get a datbase RepID and then try to open the database by RepID with
appDB = s.getDbDirectory(null).openDatabaseByReplicaID(repID);
if (appDB.isOpen()){
theMap.put(thisKey, repID);
}else{
theMap.put("DB " + thisKey, "Is Not Open");
}
if I have a rep copy of the database locally it opens it, if I remove the local Replica the open fails. If I change the line to:
appDB = s.getDbDirectory("Development").openDatabaseByReplicaID(repID);
the proper appDB opens. So it looks like the session thinks it is running locally because it return null for the server name. This is really strange, am I missing something? For the moment i have just hard coded the server name in the getDbDirectory but that wont work in the real world.
Is this XPiNC? That would consider the database to be running locally unless you've set the application property "Run server-based XPages on server"
String serverName = s.getEnvironmentString("ServerName", true);
or
String serverName = s.getEnvironmentString("ServerKeyFileName_Owner", true);
My program is able to connect to localhost MySQL server to get the data from it. But when I uploaded the database onto a server I'm not able to connect any more.
final static String db_url = "jdbc:mysql://***.***.***.***:3306/oyutan";
String card = cardnumber.getText();
String pinn = pincode.getText();
String pindb = null;
String pinsql = "SELECT * FROM `card` WHERE `card_number`=" + card + ";";
try {
Class.forName(jdbc_driver);
con = DriverManager.getConnection(db_url, "bilig", "199108");
ps = con.prepareStatement(pinsql);
rs = ps.executeQuery();
if (rs.next()); {
pindb=rs.getString("code")+"";
cardnumber.setText(" ");
pincode.setText(" ");
}
}
catch(Exception g) {
System.out.println("Not Found!");
g.printStackTrace();
}
I can access the database with Command line, but this gives me error "Host '...' is not allowed to connect to this MySQL server". I gave myself all the privileges I need. Do I need another program such as Tomcat, Apache, etc?
i gave myself all the privileges i need.
Apparently MySQL disagrees with you.
You GRANT permission to particular users on particular machines. Here's an example:
create database contacts;
create user contacts identified by 'contacts';
-- this next one is what you're probably missing.
grant all on contacts.* to 'contacts'#'%';
grant select on `mysql`.`proc` to 'contacts'#'%';
use contacts;
Every use of the string "contacts" above is for an example of mine that happens to use a database with that name. I created a user named 'contacts' with password 'contacts'. (Not the most imaginative naming scheme.)
Adjust the values to meet you situation.
is the database server local?
i mean is it localhost to your code?
if not, you need to add a Host to the username you are using, which is the IP your code will be running from, so the db-server allows this user to connect from remote machine.
I have created a java application in netbeans, and I intend to create an installer for the project.
For this I have created a jar file of the application, but I'm using the mysql database localhost.
How can I generate Jar File with Mysql localhost .
Can anyone help me please?
Thanks and regards
-----------------------------Edit---------------------------------------
Maybe not the best way to express myself, what I mean is that the database is created locally (localhost).
The connection of the application with the database is done this way:
Class.forName("com.mysql.jdbc.Driver");
return driverManager.getConnection("jdbc:mysql://localhost/database","root", "root");
I want to create a jar file of my application that has a database created locally.
I am going to explain a few things:
You do not need to hard - code the Connect URL into your code. This is why you are asking for ways of creating the database as localhost. I suggest you do not hard code the Connect URL in the code. Instead write it in an editable File either a Properties file or even a text file. Let the Application read the Editable file and pass the Parameters to the Code.
An Application running in your Local Machine where the database is will connect using Localhost. But a the same Application running remotely from another Machine whether in the Internet or Local access network will not Connect this way.That is why I am insisting on NOT Hard-Coding the Connect String.
The database Name, user, and Password Including the Host will change from time to Time depending on which environment the Application is running in. So again if the environment changes and the variables are not the same the Application will Not Connect to the database.
Suggestion:
User a Properties file:
db.host=192.168.1.23
db.user=root
db.password=root
db.dbname=database
Load the file as a Properties file:
Properties prop = new Properties();
InputStream input = null;
try {
input = new FileInputStream("config.properties");
// load a properties file
prop.load(input);
// get the property value and print it out
System.out.println(prop.getProperty("db.host"));
System.out.println(prop.getProperty("db.user"));
System.out.println(prop.getProperty("db.password"));
System.out.println(prop.getProperty("db.dbname"));
//PASS YOUR CONNECT STRING
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://" + prop.getProperty("db.host") + "/" + prop.getProperty("db.dbname"), prop.getProperty("db.user"), prop.getProperty("db.password"));
} catch (IOException ex) {
ex.printStackTrace();
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
This way you will never have to worry about what database the application is running on as you will just have to edit the config.properties and the Application will do the rest.
I hope I gave you an answer or better still other ideas on how to handle your situation.