I got a problem about testing db connection. It was a handed over Java application in Eclipse. (which I am not familiar with it).
The app used JDBC to connect with Oracle and put the db information inside the context.xml. I tried to add different System.out.println() in the DBconn.java, but didn't show any log in console window. Any suggestion to me for testing the connection?
Related
I have created a java program that connects to a jdbc db and performs crud applications. I am done with the coding part but after I deployed it, i am running it and there seems to be no connection to the database since when i run a select query to see all data the table is empty. Any suggestions?
I used wampserver and thinks worked fine, now i don't need to start netbeans services to get connnection to the db
I am currently making a piece of software as a project in college. I have my program hooked up to a database to store and retrieve information about students after they enroll. I was bored and clicked on the JAR file while i did not have workbench opened, but i could still log in to the system and retrieve information.
My lecturer told us, during the lecture about implementing a database, that we needed workbench up and running to achieve the maximum functionality. Was she wrong?
When a MySQL (or any other SQL) server is running, you can always connect to it (technically, of course you may need username/password and you may have to care about firewall restrictions). The MySQL Workbench is just another client that connects to the database, so it is not needed to be running to let a Java program establish a connection to the database.
Thoughts: I think your lecturer meant that you will not be able to check whether all your queries where executed correctly when not having another view onto the database to check the data.
The MySQL server is running regardless of whether or not MySQL Workbench (the database administration tool) is active/running or not. Those are two different things.
Moreover, you are doing the same that the tools is doing: connecting to the running MySQL server instance in order to do some actions.
In java, I use jdbc connect to sqlite. the following sentence works,
Connection conn =DriverManager.getConnection("jdbc:sqlite:C://Users//13149//Desktop//SqliteDB0.sqlite");
When I replace this with the following one.
Connection conn =DriverManager.getConnection("jdbc:sqlite://localhost:3306//Database//SqliteDB0.sqlite")
The first time, it does not give any error message, only stop there. However, as I run it again, it always gives error message. Anyone can help me? Thanks.
Maybe you have gotten the wrong idea. A SQLite database is simply a file...so, the first setup you provided works fine.
The setup you provided would have worked fine on MySQL, for example, since there's a database server running on 3306 port. Since SQLite isn't a client/server database, but a local file, the only viable option is pointing to its physical file.
In case this second setup is supposed to be running on your application server, you just have to create the SQLite physical file and point the connection URL to it, just like you did in first place.
If you really need, for example, to have the database running on another server (different from your application server) you should consider migrating to MySQL/PostgreSQL. Both of them will allow you client/server connection.
I'm using a derby db in my JavaFX app, everything works fine, but when I connect to my db in netbeans to check out some records, and then start my app again, I get this error:
Another instance of Derby may have already booted the database
I disconnect from the db but I still get the exception, it is resolved when I restart my pc.
How can I resolve this?
In embedded mode only one process is allowed to access the Derby database files. If you open the database with netbeans to see what's going on, then your JavaFX application would be the second process accessing the database files in embedded mode. But the files are still open in netbeans.
During development it is often necessary to view the database contents at the same time your application accesses the database. You can start a Derby Network Server and access the database in client mode instead embedded. Be sure to switch the connection strings for both netbeans and your JavaFX application.
When you deploy your application you can easily switch back to embedded mode by changing the connection string in your configuration.
I have a site running a Linux/Apache/MySQL/PHP stack. I would like to connect to the database from a locally run Java program. Is this possible? (Deploying the Java program to the server would be a great effort.)
Yes, of course; as long as the Java program has the correct credentials, that the user it logs in with is given proper access from the database, etc.
From the perspective of the database, it has no idea who is connecting to it or what technology they are connecting from - all it sees is just another connection.
See Establishing a Connection in the same JDBC tutorial I linked to earlier.