sqlexception

Java Oracle localhost connection error (ORA-12505)

此生再无相见时 提交于 2019-11-28 02:07:37
I am trying to currently connect to a database on my current computer. import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class Main { public static void main(String[] argv) throws Exception { Connection connection = null; try { // Load the JDBC driver String driverName = "oracle.jdbc.driver.OracleDriver"; Class.forName(driverName); // Create a connection to the database String serverName = "localhost"; String portNumber = "1521"; String sid = "xe"; String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber + ":" + sid; String username =

Obtain the Query/CommandText that caused a SQLException

ε祈祈猫儿з 提交于 2019-11-28 00:52:02
I've got a logger that records exception information for our in house applications. When we log SQL exceptions it'd be super useful if we could see the actual query that caused the exception. Is there a way we can achieve this? The SqlException does not hold a reference to the SqlCommand that caused the exception. In your logger there is no way to do this. What you could do is catch the SqlException in the method that executes the SqlCommand and wrap it in a more descriptive exception. Example: using (var command = new SqlCommand(connection, "dbo.MyProc")) { try { command.Execute(); } catch

How to know actual problem because of which SqlException is thrown?

吃可爱长大的小学妹 提交于 2019-11-27 15:38:06
I want to handle different problems, while doing database operations, differently. e.g. The operation may fail because of wrong database credentials or due to network problem. Or it may fail because the query is not correct (if string value is being passed in the int type column) In my C# code, we only have SqlException which has collection of SqlErrors . However there are many severity levels. How can i easily identify the cause of the SqlException ? How can i determine the exception is because of the connectivity problem or authentication failure or because of the problem with the query. I

java.sql.SQLException: No database selected - why?

和自甴很熟 提交于 2019-11-27 15:35:48
the last days I was trying to learn how to access mySQL databases via Java. I am able to load the driver and get a connection to the database ( at least I think so, since I don't get an exception there..) the code is: import java.sql.*; public class test { public static void main(String[] args) { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); System.out.println("driver loaded..."); } catch(ClassNotFoundException e){ System.out.println("Error in loading the driver..."+e); System.exit(0); } try { Connection dbConnection= DriverManager.getConnection("jdbc:odbc:test","root","password");

Procedure times out from ADO.NET but not in SSMS

旧街凉风 提交于 2019-11-27 08:16:49
问题 I've got a stored procedure that is giving me a SqlException because of a timeout when I run it from code (with timeout set to 30). When I run the procedure directly in Management Studio, it executes in under 1 second. I also only get the timeout when running it against a specific database. When I use other databases it finishes quickly without an error. Here is the full error message: System.Data.SqlClient.SqlException (0x80131904): Timeout expired. The timeout period elapsed prior to

architecture mismatch between the Driver and Application?

自闭症网瘾萝莉.ら 提交于 2019-11-27 07:04:01
问题 I am using JDBC to connect to my microsoft access database. I get the following exception when I try to connect to the database: java.sql.SQLException: [Microsoft][ODBC Driver Manager] The specified DSN contains an architecture mismatch between the Driver and Application I am using 64bit windows7, and I am using eclipse which is also a 64bit version My database is a microsoft access database and it seems that the driver is a 32bit driver which is causing the problem. Any help on how to solve

What does “if (rs.next())” mean?

别说谁变了你拦得住时间么 提交于 2019-11-27 04:37:35
问题 I am currently getting the error, java.sql.SQLException: Method 'executeQuery(String)' not allowed on prepared statement. because I am using PreparedStatement stmt = conn.prepareStatement(sql); and also had ResultSet rs = stmt.executeQuery(sql); in my code. I now need to remove the ResultSet line but that leaves me with having to deal with the following code: if (rs.next()) { messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("login.successful")); request.getSession(true)

How to throw a SqlException when needed for mocking and unit testing?

房东的猫 提交于 2019-11-27 01:11:53
问题 I am trying to test some exceptions in my project and one of the Exceptions I catch is SQlException . It seems that you can't go new SqlException() so I am not sure how I can throw an exception especially without somehow calling the database (and since these are unit tests it is usually advised not to call the database since it is slow). I am using NUnit and Moq, but I am not sure how to fake this. Responding to some of the answers that seem to all be based on ADO.NET, note that I am using

Java: Missing Database error

て烟熏妆下的殇ゞ 提交于 2019-11-26 23:16:52
问题 I am getting the following error: java.sql.SQLException: [SQLITE_ERROR] SQL error or missing database (no such table: apartments) In reality, the table does exist. The following is my code: try { // load the sqlite-JDBC driver using the current class loader Class.forName("org.sqlite.JDBC"); Connection connection = null; // create a database connection connection = DriverManager.getConnection("jdbc:sqlite:/Path/To/apartments.db"); System.out.println(connection.getMetaData()); Statement

Exception java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0) [duplicate]

青春壹個敷衍的年華 提交于 2019-11-26 21:53:19
问题 This question already has answers here : java.sql.SQLException Parameter index out of range (1 > number of parameters, which is 0) [closed] (2 answers) Closed 4 years ago . I'm getting this error: Exception java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0). java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0). at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055) at com.mysql.jdbc.SQLError