Page 1 of 1

mysql-server

Posted: Thu Jan 08, 2015 6:55 am
by jcaz76
I am having trouble connecting to an SQL server I set up on the raspberry pi. When I try to connect to it, I get an error(using jtds 1.3.1):
java.sql.SQLException: I/O Error: Unknown packet type 0x42

code:
Connection conn = null;
ResultSet rs = null;
String url = "jdbc:jtds:sqlserver://xxxxxxxxxx;DatabaseName=xxxxx";
String driver = "net.sourceforge.jtds.jdbc.Driver";
String userName = "xxxx";
String password = "xxxxxxxxx";
try {
Class.forName(driver);
conn = DriverManager.getConnection(url, userName, password);
System.out.println("Connected to the database!!! Getting table list...");
DatabaseMetaData dbm = conn.getMetaData();
rs = dbm.getTables(null, null, "%", new String[] { "TABLE" });
while (rs.next()) { System.out.println(rs.getString("TABLE_NAME")); }
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
conn.close();
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}



I also tried using sqljdbc but got a different error:
com.microsoft.sqlserver.jdbc.SQLServerException: The TDS prelogin response is incomplete. The target server must be SQL Server 2000 or later.

code:

try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection conn = DriverManager.getConnection("jdbc:sqlserver://xxxxxxxxxx",
"xxxxx", "xxxxxxxx");
System.out.println("connected");
Statement statement = conn.createStatement();
String queryString = "select * from testTable";
ResultSet rs = statement.executeQuery(queryString);
while (rs.next()) {
System.out.println(rs.getString(1));
}
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
}

Obviously something is wrong, I just have no idea where to start... Here is my java code to connect to it. The server version is 5.5.40-0+wheezy1 (Debian). I have tried for hours to fix this issue, but I just cant seem to get it...
Note: I have a valid connection to it, the connection is not the issue.

Re: mysql-server

Posted: Thu Jan 08, 2015 7:24 am
by mike_p
You appear to be attempting to connect to a mysql server using a driver for a Microsoft SQL server. Doomed to fail!

You may find a suitable driver here: http://www.mysql.com/products/connector/

Re: mysql-server

Posted: Thu Jan 08, 2015 7:35 am
by jcaz76
Wow, thanks! I can't believe I didn't notice that! Thank you very much!

Re: mysql-server

Posted: Thu Jan 08, 2015 7:45 am
by jcaz76
To fix it, I downloaded the .zip version, grabbed the new .jar, added it to my project as an external JAR, and boom! I had to change the DriverManager info, but that was really quick. What a day! haha