Click here to download the latest version of Microsoft JDBC Driver for SQL Server. Download Microsoft JDBC driver for SQL serverTo enable a Java program connects to Microsoft SQL Server database, we need to have a suitable JDBC driver present in the classpath.
This JDBC tutorial helps you understand how to get JDBC driver and write code for making database connection to Microsoft SQL Server from a Java client. asadmin set _mysql-pool.driver-classname=
asadmin create-jdbc-connection-pool –datasourceclassname 2.optional.MysqlConnectionPoolDataSource –restype –property user=myuser:password=mypasword:url=”jdbc\:mysql\:\/\/my_host\:my_port\/my_db_schema” myjdbc_mysql-poolĮnter admin user name> YOUR_GLASSFISH_ADMIN_USERĮnter admin password for user “YOUR_USER”> YOUR_GLASSFISH_ADMIN_PASSWORDĮnter the value for the connectionpoolid option> myjdbc_mysql-pool (the name you assigned at the end of pool creation command)Įnter the value for the jndi_name operand> jdbc/mysql-resource (the name you want to assign to hsbc resource) Go to: $glassfish_install_dir/glassfish/bin: The solution is as follows (example for mysql): Sometimes Glassfish 4 does not allow JDBC Resources creation using the GUI (apparently is a bug we have to deal with) Go to Resources → JDBC → JDBC Resources and create a new one, with these propertiesJNDI Name: MyDatabaseĪnd that’s all!! Simple, isn’t it ? Now you can access the tables bya a JNDI lookup inside you application, or using JPA, but this will be explained in another chapter.
You don’t need initially 8 connections to the database in your development machine.Set the next additional properties: Initial and Minimum Pool Size Set a zero value on this parameter. Because you choose database driver vendor MySQL you will have already specified the driver classname (). Resource type: (you can choose any other but by now is the simplest option).ĭatabase Driver Vendor: MySQL. Create a connection pool with the following properties: Open Resources\JDBC\JDBC Connection Pools.
Setting up a JDBC connection in Glassfish. INSERT INTO booreg.USERS VALUES ('dgisbert', 'Dani Gisbert', 'mypassword', INTO booreg.USRGP VALUES ('allUsers', 'dgisbert') The database is called booregĬONSTRAINT USRGPFK00 FOREIGN KEY (USID) REFERENCES ers (USID) So, I will directly create a database and two tables in this database: USERS (Users table) and USRGP (User groups). I assume you have basic knowledge about installing MySQL, accessing the database and run SQL statements against it.
If you want some details about software that I am using check my development environment. I assume that you have installed Glassfish and MySQL. In this case we will create a little database with MySQL and I will setup a JDBC connection to use it later from a program.
Following the series of articles I am writing for newcomers to Java EE world and Glassfish, today I will make an introductory work that will allow us to work with databases.