CSQL: NetBeans Configuration for CSQL JDBC DRIVER

CSQL JDBC driver supports connection through driver manager, data sources object, connection pooling data source object. For Netbeans IDE, you need to configure properly for CSQL database.

Connection Through DriverManager

For the connection through DriverManager object, you need to start the CSQL server in one terminal. In another terminal run . ./setupenv.ksh in csql root directory , then go to Netbeans /bin directory and run ./netbeans . Create a java applications with following code.

public class Main {

public static void main(String[] args) {

try {

Class.forName(“csql.jdbc.JdbcSqlDriver”);

Connection con = DriverManager.getConnection(“jdbc:csql”, “root”, “manager”);

if(con!=null){System.out.println(“Connection Exstablished”);}

else {System.out.println(“Connection failed”);}

Statement cStmt = con.createStatement();

cStmt.execute(“CREATE TABLE T1 (f1 integer, f2 char (20));”);

System.out.println(“Table T1 is created”);

cStmt.close();

con.close();

}catch(Exception e) {

System.out.println(“Exception in Test: “+e);

e.printStackTrace();

}

}

Go to the projects ->libraries, right click on it and go Add JAR/Folders…Give the jar file path and click on OK . Now run Applications.

Connection Through DataSource

For DataSource Configuration, set as mention above with a web application. For example use the following jsp code.

<html>

<head>

<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″>

<title>JSP Page</title>

</head>

<body>

<%

try{

out.println(“Table created on csql “);

javax.naming.Context cxc= new javax.naming.InitialContext();

javax.sql.DataSource ds = (javax.sql.DataSource) cxc.lookup(“jdbc/bijaya”);

java.sql.Connection conn=ds.getConnection(“root”, “manager”);

out.println(“Table created on csql “);

java.sql.Statement stmt=conn.createStatement();

stmt.execute(“CREATE TABLE papu (f1 int,f2 int);”);

out.println(“Table created on csql “);

conn.close();

} catch (java.sql.SQLException e){

out.println(“An error occurred.”);

}

%>

</body>

</html>

Start application server, go to ‘application sever admin console‘ for connection pool setup. Go to application sever, click on JVM settings, from their in Path Settings set Classpath Prefix and Native Library Path Suffix

Now go to Resources ->JDBC->Connection Pools, create new connection pool with additional propertics with URL as csql jdbc url, user, password properties and Datasource Classname as csql.jdbc.JdbcSqlDataSource. Now save and ping for successful connection. Create a JDBC Resources name.

Now run the web application.

free invisible web counter