<< Squirrel SQL Client - TOC - Eclipse IDE for Java Developers >>
CSQL JDBC driver supports connection through driver manager, data sources object, connection pooling data source object. For Netbeans IDE, a proper configuration is required to connect to CSQL database.
For the connection through DriverManager object, The CSQL server should start in one terminal In another terminal run,.( . ./setupenv.ksh) in csql root directory , Find the Netbeans /bin directory and run. . /netbeans. After executing this script Netbeans editor will open up. Now the next step is to create a java application using the below 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();
}
}
After writing the above java code, find the below points, Find the path projects ->libraries, and right click on it, Add JAR/Folders... It will show a dialog box.
In the dialog box specify jar file path and click on OK button. Now run applications.
For DataSource configuration, the setting is needed as mentioned 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
{
System.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");
System.out.println ("Table created on csql ");
java.sql.Statement stmt=conn.createStatement ();
stmt.execute ("CREATE TABLE papu (f1 int, f2 int);");
System.out.println ("Table created on csql ");
conn.close();
} catch (java.sql.SQLException e)
{
System.out.println("An error occurred.");
}
%>
</body>
</html>
Find the below points for CLASSPATH setting and to run the application. Now Start application server, Follows the below points to do this, Find the 'application sever admin console' for connection pool setup. Find the application sever, click on JVM settings, from their in Path Settings Set Classpath Prefix and Native Library Path Suffix Find the Resources->JDBC->Connection Pools path, Create new connection pool with additional propertics with URL from the CSQL’s available jdbc urls. User, Password properties and Datasource Classname as csql.jdbc.JdbcSqlDataSource. Save and ping for successful connection. Now a JDBC Resources name will be creating. Run the web application.
For the connection pool setup, go through section 5.10.2.1. Set as mentioned there. Make only changes in Resources->JDBC->Connection Pools ‘Datasource Classname’ as csql.jdbc.JdbcSqlConnectionPoolDataSource and ‘Resource Type’ as javax.sql.ConnectionPoolDataSource. Then run web application.
<< Squirrel SQL Client - TOC - Developing CSQL application with Eclipse IDE for Java Developers >>