Does anyone know if the SQuirreL SQL Client is compatible with QODBC? If not is there a plugin for SQuirreL to enable so?
Any insight would be appreciated as I have never used either.
An Example of QODBC Driver working with the Java ODBC Bridge Product
Note: Below are some example code from one of our happy customers:
// QuickBooks variables
Connection con =null;
Statement stmt = null;
ResultSet rs = null;
// parameters for QuickBooks database
static final String url = "jdbc:odbc:quickbooks";
// "quickbooks" is a System DSN that is the name of the QODBC driver
// On WindowsXP it can be set up at Control Panel > Administrative Tools >
// Data Sources (ODBC)
static final String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
public static void main(String[] args) throws Exception {
InsertCustomers t = new InsertCustomers();
}
public InsertCustomers() throws Exception {
try {
Class.forName(driver);
con = DriverManager.getConnection(url);
stmt = con.createStatement();
System.out.println("Querying QB customer table");
rs = stmt.executeQuery("SELECT * FROM customer");
JDBC is supported by QODBC - thanks!
http://support.flexquarters.com/esupport/index.php?/Knowledgebase/Article/View/383/0/how-can-qodbc-driver-work-with-the-java-odbc-bridge-product
Related
we tried to use dbcp and c3p0 as database connection pooling in our jooq environment. Both work fine for SELECT statements but CREATE and UPDATE statements does not release the connection.
We initialized the dbcp like:
public static DataSource setupDataSource(String dbUrl, String dbUserName, String dbPassword) {
ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(dbUrl, dbUserName, dbPassword);
PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, null);
ObjectPool<PoolableConnection> connectionPool = new GenericObjectPool<>(poolableConnectionFactory);
poolableConnectionFactory.setPool(connectionPool);
PoolingDataSource<PoolableConnection> dataSource = new PoolingDataSource<>(connectionPool);
return dataSource;
}
Then we get connection for each query:
Connection dbConnection = null;
try {
dbConnection = dataSource.getConnection();
} ....
DSLContext dslContext = DSL.using(connection, dialect);
Out create statement looks like:
protected final DSLContext jooq;
public E add(E entity) throws Exception {
E transformedEntity = null;
try {
R persisted;
persisted = jooq.insertInto(transformator.getTable())
.set(transformator.createRecord(entity))
.returning()
.fetchOne();
transformedEntity = transformator.getEntityFromTableRecord(persisted);
} catch (DataAccessException e) {
...
}
return transformedEntity;
}
And in the end we close the connection with:
dbConnection.close();
The problem is that the connections stay open and after the connection pool is full no connection can be created. Do I need to close the statements and resultsets? And if yes, how can I do this with jooq?
The easiest way to do this with jOOQ is to pass the data source directly to jOOQ. Instead of:
Connection dbConnection = null;
try {
dbConnection = dataSource.getConnection();
} ....
DSLContext dslContext = DSL.using(connection, dialect);
... write:
DSLContext dslContext = DSL.using(dataSource, dialect);
That way, jOOQ will manage connection lifecycles for you. Otherwise, I suspect you simply have some situations where your connection still leaks and isn't closed properly
im trying to use phpMyAdmin as DB on my javafx apps but everytime I open my apps, no data are being displayed and there are errors.
This is my Connect class:
public java.sql.PreparedStatement connectDatabase() throws Exception{
java.sql.Connection conn = java.sql.DriverManager.getConnection("jdbc:mysql://sql6.freemysqlhosting.net/hostingserver:3306","dbUserName","dbPassword");
java.sql.PreparedStatement ps = conn.prepareStatement("Select ORNUM,AMOUNT from receipt");
return ps;
}
From groovy script in SoapUI I need to connect to a mysql database to perform some queries. The problem is that due to security reasons no external access is possible.
Therefore it is required to get an ssh access (like a tunnel) and invoke mysql locally.
Initially I was reading the below project properties and then connect to mysql:
ServerUrl=jdbc:mysql://10.255.255.122:3306/db
ServerDbUser=user
ServerDbPwd=password
ServerDriver=com.mysql.jdbc.Driver
def url=testRunner.testCase.testSuite.project.getPropertyValue("ServerUrl")
def usr=testRunner.testCase.testSuite.project.getPropertyValue("ServerDbUser")
def pwd=testRunner.testCase.testSuite.project.getPropertyValue("ServerDbPwd")
def driver=testRunner.testCase.testSuite.project.getPropertyValue("ServerDriver")
com.eviware.soapui.support.GroovyUtils.registerJdbcDriver(driver)
sqlServer = Sql.newInstance(url, usr, pwd, driver)`
But this didn't work so now it is required to establish first a ssh connection to the server with the IP 10.255.255.122 and then open the mysql connection locally. So I guess the Server Url will change to:
ServerUrl=jdbc:mysql://127.0.0.1:3306/db
But I don't know how to set first the ssh connection to the server.
Can someone help me with this?
Thanks.
Have a look at http://forum.soapui.org/viewtopic.php?t=15400 and connect to remote mysql database through ssh using java
It will give you an idea about implementing it in soapUI.
Below is the code by Ripon Al Wasim which is available as an answer at the stackoverflow link mentioned above
package mypackage;
import java.sql.*;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;
public class UpdateMySqlDatabase {
static int lport;
static String rhost;
static int rport;
public static void go(){
String user = "ripon";
String password = "wasim";
String host = "myhost.ripon.wasim";
int port=22;
try
{
JSch jsch = new JSch();
Session session = jsch.getSession(user, host, port);
lport = 4321;
rhost = "localhost";
rport = 3306;
session.setPassword(password);
session.setConfig("StrictHostKeyChecking", "no");
System.out.println("Establishing Connection...");
session.connect();
int assinged_port=session.setPortForwardingL(lport, rhost, rport);
System.out.println("localhost:"+assinged_port+" -> "+rhost+":"+rport);
}
catch(Exception e){System.err.print(e);}
}
public static void main(String[] args) {
try{
go();
} catch(Exception ex){
ex.printStackTrace();
}
System.out.println("An example for updating a Row from Mysql Database!");
Connection con = null;
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://" + rhost +":" + lport + "/";
String db = "testDB";
String dbUser = "wasim";
String dbPasswd = "riponalwasim123";
try{
Class.forName(driver);
con = DriverManager.getConnection(url+db, dbUser, dbPasswd);
try{
Statement st = con.createStatement();
String sql = "UPDATE MyTableName " +
"SET email = 'ripon.wasim#smile.com' WHERE email='peace#happy.com'";
int update = st.executeUpdate(sql);
if(update >= 1){
System.out.println("Row is updated.");
}
else{
System.out.println("Row is not updated.");
}
}
catch (SQLException s){
System.out.println("SQL statement is not executed!");
}
}
catch (Exception e){
e.printStackTrace();
}
}
}
I'm using GWT to connect to MYSQL.
But I every time I got the error as follows:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
I have putthe driver files to the war\WEB-INF\lib. And the driver has been load.
For a normal JAVA project I can use the same code to find file in MYSQL.
But why can't use the same code in GWT project?
public class GreetingServiceImpl extends RemoteServiceServlet implements
GreetingService {
public String greetServer(String input) throws IllegalArgumentException {
Connection conn = null;
String url ="jdbc:mysql://localhost:3306/pcmorder";
String driver = "com.mysql.jdbc.Driver";
String user = "root";
String pass = "123456";
//String query = "SELECT id FROM tb_user WHERE username = ";
String sql=null ;
String[] namelist;
int name1=0 ;
try {
Class.forName(driver).newInstance();
System.out.println("OK");
conn = DriverManager.getConnection(url, user, pass);
Hi i have the following file to connect mysql database to html files. But i am having trouble connecting it. Can anyone tell me where i find the locations.
What should i replace "jdbc:mysql://localhost/zulfiqar" with for it to work on my computer? where do i find this?
And is there anything else i have to change to make it work on my computer? this was a piece of code i found on the internet which i am trying to make work so i can understand how to do it, but i am struggling.
Thanks in advance!
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ServletUserEnquiryForm extends HttpServlet{
public void init(ServletConfig config) throws ServletException{
super.init(config);
}
/**Process the HTTP Get request*/
public void doPost(HttpServletRequest req,
HttpServletResponse res) throws ServletException,
IOException{
String connectionURL = "C:\Program Files(x86)\MySQL Server 5.0\bin\mysql.exe";
Connection connection=null;
ResultSet rs;
res.setContentType("text/html");
PrintWriter out = res.getWriter();
//get the variables entered in the form
String uId = req.getParameter("userId");
String fname = req.getParameter("firstname");
String sname = req.getParameter("surname");
String address1 = req.getParameter("address1");
String address2 = req.getParameter("address2");
String town = req.getParameter("town");
String county = req.getParameter("country");
String zipcode = req.getParameter("zipcode");
try {
// Load the database driver
Class.forName("org.gjt.mm.mysql.Driver");
// Get a Connection to the database
connection = DriverManager.getConnection
(connectionURL, "root", "admin");
//Add the data into the database
String sql =
"insert into emp_details values (?,?,?,?,?,?,?,?)";
PreparedStatement pst =
connection.prepareStatement(sql);
pst.setString(1, uId);
pst.setString(2, fname);
pst.setString(3, sname);
pst.setString(4, address1);
pst.setString(5, address2);
pst.setString(6, town);
pst.setString(7, county);
pst.setString(8, zipcode);
int numRowsChanged = pst.executeUpdate();
// show that the new account has been created
out.println(" Hello : ");
out.println(" '"+fname+"'");
pst.close();
}
catch(ClassNotFoundException e){
out.println("Couldn't load database driver: "
+ e.getMessage());
}
catch(SQLException e){
out.println("SQLException caught: "
+ e.getMessage());
}
catch (Exception e){
out.println(e);
}
finally {
// Always close the database connection.
try {
if (connection != null) connection.close();
}
catch (SQLException ignored){
out.println(ignored);
}
}
Some additional information about how it's failing might be useful.
1) Is it failing to make the socket connection (implying your service isn't running), or
2) Did it fail to initialize the driver? I'm not familiar with the one you listed. A more common alternative is "sun.jdbc.odbc.JdbcOdbcDriver".
3) Did you connect and simply fail authentication with user "root" and password "admin"?
What should i replace "jdbc:mysql://localhost/zulfiqar" with
Ans: It is the connection url. It does mean your MySQL database is running on localhost server (with default port) and you are connecting to 'zulfiqar' database. So first line under doPost() should be :
String connectionURL = "jdbc:mysql://localhost/zulfiqar";
Next, you are using org.gjt.mm.mysql.Driver driver for JDBC connection. It was initially developed by a hobbyist. It's later donated to MySQL where they renamed the package/classname. The old classname is kept for backwards compatibility reasons, but you should update it to com.mysql.jdbc.Driver and add mysql-connector-java-*-bin.jar in your WEB-INF/lib folder.
Next thing you are using :
connection = DriverManager.getConnection(connectionURL, "root", "admin");
So you are loading a connection from the connectionURL and accessing it with root user and admin password. Make sure these are correct in your case.
Last point is, you are inserting into emp_details table. Make sure you have this table already created in zulfiqar database with all required columns. And the number of '?' marks in the sql string should match the number of times you are doing pst.setString(index, data), otherwise you will get Invalid parameter index error.