Help on database connection

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Help on database connection

vijethasrujana
Hi guys,

i am new to this forum,
i have an issue with databse connection using selenium,in my project we are using interbase for connecting to that database through selenium i got an exception like "java.lang.NullPointerException"

  String urldbname=("jdbc:interbase://localhost:5354/Work/employee.GDB");
                String driver = "interbase.interclient.Driver";
                String userName = "SYSDBA";
                String password = "masterkey";
 Class.forName(driver).newInstance();// create object of Driver
                          conn = DriverManager.getConnection(urldbname,userName,password);

iam trying with the above data but always i am getting the nullpointer exception.

please help/correct me on this...
pls ignore my post if it is wrong place to ask this question....?
Reply | Threaded
Open this post in threaded view
|

Re: Help on database connection

Chester
If you are using MySql try this


 private void Checkdb() {
                                Connection connection = null;
                                Statement statement =null;
                                try{
                                        System.out.println("connecting to db Driver");
                                        Class.forName("com.mysql.jdbc.Driver");
String host= "";
String user="";
String pass="";
String db_name="";
String query="";
                                        connection =
DriverManager.getConnection("jdbc:mysql://"+host,TestVariables.user,TestVariables.pass);
                                        statement =connection.createStatement();
                                        statement.execute("USE "+db_name+";");
                                        ResultSet result = statement.executeQuery(query);
                                         result.last();
                                         int size = result.getRow();
                                         result.beforeFirst();
                                   
                                        while(result.next()) {
int columNumber= 1;
                                                System.out.println("selected colum value: "+result.getInt(columNumber));
                                                       
                               
                                        }
                                       
                                }
                                catch (ClassNotFoundException error) {
                                       
                                        System.out.println("Cant find host "+error.getMessage());// TODO: handle exception
                                       
                                }
                                catch (SQLException error)
                                {
                                        System.out.println("SQL Eskase "+error.getMessage());
                                       
                                }finally
                                {
                                        if (connection !=null) try {connection.close();}catch(SQLException ingore){}
                                        if (connection !=null) try {statement.close();}catch(SQLException ingore){}


                                }
                               

                }

Make sure you import the following
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


let me know if it worked
Reply | Threaded
Open this post in threaded view
|

Re: Help on database connection

vijethasrujana
Hi chester,
thanks for your reply
here i am using IBExpert (interbase)
claa.forName("InterBase.interclient.Driver")
and the jar file is "interclient.jar"