caracol_mix Posted August 9, 2013 at 05:02 PM Report #521373 Posted August 9, 2013 at 05:02 PM (edited) olá a todos... antes de mais peço desculpa se não coloquei o tópico no sitio correcto. Bem o meu problema é o seguinte, quando tento fazer a ligação através do java a uma base em de dados (sql server) é dado o seguinte erro: java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/database at java.sql.DriverManager.getConnection(DriverManager.java:596) at java.sql.DriverManager.getConnection(DriverManager.java:215) at DirectoryWatcher.dataBase(dataManipulate.java:38) at DirectoryWatcher.printEvent(dataManipulate.java:153) at DirectoryWatcher.run(dataManipulate.java:183) at java.lang.Thread.run(Thread.java:724) não sei como instalar o tal driver este é o código que estou a usar: Connection con = null; PreparedStatement pst = null; try ( // Step 1: Allocate a database "Connection" object Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/database", "user", "pass"); // MySQL Connection connc = DriverManager.getConnection("jdbc:odbc:ebookshopODBC"); // Access // Step 2: Allocate a "Statement" object in the Connection Statement stmt = conn.createStatement(); ) { // Step 3: Execute a SQL SELECT query, the query result // is returned in a "ResultSet" object. String strSelect = "SELECT * from tbl"; System.out.println("The SQL query is: " + strSelect); // Echo For debugging System.out.println(); ResultSet rset = stmt.executeQuery(strSelect); // Step 4: Process the ResultSet by scrolling the cursor forward via next(). // For each row, retrieve the contents of the cells with getXxx(columnName). System.out.println("The records selected are:"); int rowCount = 0; while(rset.next()) { // Move the cursor to the next row String title = rset.getString("title"); double price = rset.getDouble("price"); int qty = rset.getInt("qty"); System.out.println(title + ", " + price + ", " + qty); ++rowCount; } System.out.println("Total number of records = " + rowCount); } catch(SQLException ex) { ex.printStackTrace(); } agradecia muito se alguem me pudesse ajudar ..... Obrigado 🙂 Edited August 9, 2013 at 05:58 PM by Baderous geshi
HappyHippyHippo Posted August 9, 2013 at 05:23 PM Report #521375 Posted August 9, 2013 at 05:23 PM quando tento fazer a ligação ... a uma base em de dados (sql server) é dado o seguinte erro: Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/database", "user", "pass"); MySQL e MSSQL são base de dados diferentes ... IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
saca-rolhas Posted August 12, 2013 at 06:16 PM Report #521544 Posted August 12, 2013 at 06:16 PM Boas aquele cujo anda com a casa às costas, Desconheço tal declaração JDBC: Connection connc = DriverManager.getConnection("jdbc:odbc:ebookshopODBC"); // Access vê o 4º post desta thread http://www.portugal-a-programar.pt/topic/61714-conexao-base-de-dados/ isso é para MySQL se quiseres um exemplo de MSSQL diz The worst part of censorship is ****
caracol_mix Posted August 14, 2013 at 04:32 AM Author Report #521681 Posted August 14, 2013 at 04:32 AM Boas desculpem só responder agora... quando criei o post enganei-me a copiar o código peço as minhas desculpas por isso...mas já resolvi o meu problema que era quando eu usava uma Statement para todas as operações mas de qualquer das maneiras obrigados por me responderem...abraço a todos 😉
jpfelgueiras Posted August 23, 2013 at 12:24 AM Report #522437 Posted August 23, 2013 at 12:24 AM Boas aquele cujo anda com a casa às costas, Desconheço tal declaração JDBC: Connection connc = DriverManager.getConnection("jdbc:odbc:ebookshopODBC"); // Access vê o 4º post desta thread http://www.portugal-a-programar.pt/topic/61714-conexao-base-de-dados/ isso é para MySQL se quiseres um exemplo de MSSQL diz era só uma questão de pesquisares http://en.wikipedia.org/wiki/JDBC_driver http://www.roseindia.net/jdbc/Jdbc-odbc-connection.shtml Podes usar este segundo link para o odbc
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now