Connect to a MySQL DB with JSP through another class - java

Can I connect to a MySQL DB with JSP through another class?
Here is my my own suggestion:
...<body>
<h3>The User List</h3>
<br>
<%
// JSP/Java kode
UsersDAPInterface users = new UserDAPClass(); // This java class contains mysql connection etc.
%>
</body>...
When I do this, I get a lot of errors and exceptions, including ClassNotFound, NullPointer etc.
I also got this:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
Which should mean that it doesn't have the mysql driver.. But I have imported the mysql driver so I don't know if it should be imported in a different way than usually.
Any suggestions?

Make sure that this jar file in present in WEB-INF/lib folder of your application, as long as its present there, this issue should not come.

<jsp:useBean/> use this action to load any class to jsp. This is best practice.
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
This exceptions occurs due to your MySQL Connector Driver is not laoded. Use an IDE to load the driver. Manually check whether the com.mysql.jdbc.Driver is founded by writing it on Java class.

Download lib file from here and put it in your lib folder of your application. Have no idea what IDE are you using, but on Netbeans, take following steps:
Right click on your project
Select properties
In the category panel, select Libraries
Add jar folder just downloaded from Maven
You are ready.

You need to add jdbc driver class in your webapp library.

Related

Where do I download sajdbc4.jar from?

I do not have SQL Anywhere installed. I have tried jconn4, and jconn3, I have also tried, jodbc4, and none of them would do what I need.
I need a pure java, type 4, jdbc driver for Sybase, and as far as I can ascertain that's sajdbc.jar. But it is nowhere to be seen. I badly need this file. Is there anyone who can tell me where I can go to download this file ?
i met the same issue these days, and i just fix this :)
First, visit this site and register : https://www.sap.com/cmp/syb/crm-xu15-int-asewindm/index.html
than u can download "ASE_Suite.winx64.zip"
open this zip file and you can see the view like this:
and than click "setupConsole.exe", you can see:
select custom , and you may select jconnect4, like this:
At the end, you can find jconnect at the place
hope this would help:))
Quoting the SQL Anywhere JDBC drivers documentation:
The Java component of the SQL Anywhere JDBC 4.0 driver is included in the sajdbc4.jar file installed into the Java subdirectory of your SQL Anywhere installation. For Windows, the native component is dbjdbc12.dll in the bin32 or bin64 subdirectory of your SQL Anywhere installation; for Unix, the native component is libdbjdbc12.so. This component must be in the system path.

After Installing NetBeans 8.0.2 with GlassFish 4.1 Cannot Connect to sample Database

I installed NetBeans 8.0.2 with glassfish-4.1. The sample folder is present under C:\Users\Username.netbeans-derby. When I bring up NetBeans and go to the Services tab the connection to sample is present: jdbc:derby://localhost:1527/sample [app on APP] but sample is not listed under Java DB so when I try to connect to sample I get the following error "Unable to connect. Cannot establish a connection to jdbc:derby://localhost1527/sample using org.apache.derby.jdbc.ClientDriver (The connection was refused becuase the database sample was not found)."
Right click on Java DB select Create Database.
use as Database Name 'sample'
use as User Name 'app'
leave the password empty
edit
Seems there is a broken database or maybe one from an earlier Netbeans installation. Remove the sample connection in Netbeans and remove the directory %USERPROFILE%\.netbeans-derby\sample. Recreate the sample database as described above.
I had a broken database from an earlier version too, and then couldn't connect to the sample db.
I simply had to delete the .netbeans-derby directory,
then reinstalled Netbeans,
and is was ok, then.
The same thing happened to me and re-installing NetBeans did not help. After poking around the databases for a bit, I finally got mine working using the following process.
Create a new database with any properties (i.e. name, user, pw)
Navigate to your user directory \.netbeans-derby\{name}\
Copy service.properties file and paste in \.netbeans-derby\sample\
Reconnect to sample database in NetBeans
A couple extra notes:
If you configured your NetBeans database to a different location, use that location in step 2.
You may need to delete and re-create the existing sample database connection in NetBeans for it to pickup the new service.properties file.

How to connect to Firebird using LibreOffice

I have to create some reports using LibreOffice. I need to connecto a Firebird database using JDBC. I installed the driver (adding it to the classpath) and configured my connection to use
firebirdsql://server:alias
org.firebirdsql.jdbc.FBDriver
when I test the class I get this error:
"could not load driver class org.firebirdsql.jdbc.FBDriver"
javax/resource/ResourceException
I tried in another machine and got the same message. Is there anything extra that should be added to classpath? What I´m missing here? I have both JRE and JDK installed and I´m using the first located in C:\Program Files(x86)\Java\jre7. There is no classpath environment variable defined nor global or for the user
The above continues to be correct for Jaybird 4.0. Here are instructions in a little more detail, based on Debian 10. This is for an existing Firebird database that you can access already (i.e. can connect to and have an established username and perhaps pw).
Start LibreOffice but not Base - use Calc or just the general LibreOffice icon. Go to Tools, Options, LibreOffice and click on Advanced (in the top section, not in the Base options). Check the version number of the installed JRE. Leave the Advanced window open.
Download the corresponding version of the Jaybird zip file and unpack it. As pointed out by Mark Rotteveel in the original answer, jaybird has a dependency which may mean the bare jar file won't work. The simplest way around that is to use the "full" jar file:
jaybird-full-4.0.0.java11.jar
You may wish to move it into /usr/share/java for consistency but will probably need root permissions to do so.
Back in LibreOffice, click on the Class Path button in the Advanced window, then on Add Archive and add the .jar file. Close the Advanced window and restart LibreOffice.
Connecting: start LO Base. The Database Connect Wizard will appear. Select
"Connect to an existing database". Specify JDBC as the driver and click Next.
Base supplies the jdbc: portion of the connect string, so add
firebirdsql:oo://host[:port]//<path to database file>
So, for example:
firebirdsql:oo://localhost:3050//home/dave/Firebird/employee.fdb
Note two occurances of "//" when using a full path.
When using an alias, there's only one set:
firebirdsql:oo://localhost:3050/employee
The JDBC driver class is:
org.firebirdsql.jdbc.FBDriver
Click Test Class to confirm that it is working. If not, retrace the steps above. The class test is independent of the connection string so no need to fill in both as you troubleshoot.
From that point on it should be self-evident. You'll end up with a .odb file that you can use to create Views, Reports, etc. on the industrial-strength Firebird back end.
Jaybird has a required dependency on JCA (Java Connector Architecture), specifically JCA 1.5 (although newer should work as well), as documented in the Jaybird 2.2.5 releasenotes,
This means you need to include either connector-api-1.5.jar (from the lib folder) on the classpath, or you need to use jaybird-full-2.2.5.jar as that includes the classes from connector-api-1.5.jar.
Also your url is incorrect on two things: The format of the url is
jdbc:firebirdsql[:<subprotocol>]://<host>[:<port>]/<path-or-alias>
Which mean that :alias is wrong (it should be /alias). And as also remarked by Gord Thompson in the comments, you need to use the subprotocol oo, so you need to use protocol prefix jdbc:firebirdsql:oo to address difference in interpretation on JDBC, as also documented here. So your url should probably look like:
jdbc:firebirdsql:oo://server/alias

java.lang.ClassNotFoundException: Class com.ibm.db2.jcc.DB2Driver not found in Worklight platform or project

I try to test an sql adapter that connects to db2 but I get the following result:
java.lang.ClassNotFoundException: Class com.ibm.db2.jcc.DB2Driver not found in Worklight platform or project
here is my code:
<dataSourceDefinition>
<driverClass>com.ibm.db2.jcc.DB2Driver</driverClass>
<url>jdbc:db2://localhost:50000/WLTEST</url>
<user>db2admin</user>
<password>db2admin</password>
</dataSourceDefinition>
any idea what is going wrong?
Add the two jars:
db2jcc.jar
db2jcc_license_cu.jar
Add them to the libraries jar folder.
Do you mean that your Worklight database is DB2-based? If yes,
make sure to also edit worklight.properties with the correct DB2 setup
Also make sure that:
the DB2 connector driver exists in the server\lib folder

Netbean6.9 --- is there xml to define for database connection?

Goal:
Create Netbean project and put on repository (any). When other developers check out the Netbean project, they can "open project" from Netbean IDE and press execute to open browser and start testing web application.
I wrote REST web app (Toplink-essential, JAX-RS, SQL Server 2008) and this is the Netbean project other people want to open in Netbean IDE.
It's working actually except that when someone "open project" in Netbean, she still has to go to Data Source tab (next to Project and File tab), then manually create database connection by filling in the popup form (i.e typing host, db name, pick driver etc).
I found out under nbproject/setup/sun-resource.xml db drivers and name/password are defined but we had to do the first step (which is filling the popup form described earlier)
Is there way to eliminate the step? That means I can somewhere define in xml ???
Please let me know if you need more clarification.
i would comment on your post, but no such option for me atm, so have to post an answer.
What database conenction are you using ?
And try to implement a properties file rather than xml file !! and then its pretty straight forward, something like this:
MySQL
hibernate.dialect = org.hibernate.dialect.MySQLInnoDBDialect
hibernate.connection.driver_class =
com.mysql.jdbc.Driver
hibernate.connection.url =
jdbc:mysql://localhost/ - . . . -
hibernate.connection.username = root
hibernate.connection.password =
this might help
http://netbeans.org/kb/docs/java/project-setup.html#ide-concepts

Categories