java - No connection configured -


how can configure connection fix bug? use mysql , jdbc.

public static void savecalllink(string oktell_login, string link)         throws sqlexception {     connection conn = dbconnection.getdatasource().getconnection();     dsl.using(conn)             .insertinto(calls)             .columns(calls.user_id, calls.call_link)             .values(                     dsl.select(users.id)                             .from(users)                             .where(users.oktell_login.equal(oktell_login))                             .fetchone().value1()                     , link             ).execute();     conn.close(); } 

sorry, log added.

org.jooq.exception.detachedexception: cannot execute query. no connection configured org.jooq.impl.abstractquery.execute(abstractquery.java:316) org.jooq.impl.abstractresultquery.fetchlazy(abstractresultquery.java:365) org.jooq.impl.abstractresultquery.fetchlazy(abstractresultquery.java:352) org.jooq.impl.abstractresultquery.fetchone(abstractresultquery.java:517) org.jooq.impl.selectimpl.fetchone(selectimpl.java:2868) ru.avito.model.callmodel.savecalllink(callmodel.java:33) ru.avito.web.oktelllistener.savecallrecord(oktelllistener.java:31) sun.reflect.nativemethodaccessorimpl.invoke0(native method) sun.reflect.nativemethodaccessorimpl.invoke(unknown source) sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source) java.lang.reflect.method.invoke(unknown source)

your mistake here:

dsl.using(conn)    .insertinto(calls)    .columns(calls.user_id, calls.call_link)    .values(        dsl.select(users.id)           .from(users)           .where(users.oktell_login.equal(oktell_login))           .fetchone().value1() // query cannot executed        , link    ).execute(); 

the query ran in middle of insert statement cannot executed because has no configuration (context) attached it. general rule of thumb, remember:

  • dslcontext creates queries "attached" dslcontext.configuration(), , can executed directly
  • dsl creates queries "unattached", , cannot executed, embedded in other queries

there 2 solutions:

1. attach nested select

dsl.using(conn)    .insertinto(calls)    .columns(calls.user_id, calls.call_link)    .values(        dsl.using(conn) // use dslcontext, not dsl here           .select(users.id)           .from(users)           .where(users.oktell_login.equal(oktell_login))           .fetchone().value1()        , link    ).execute(); 

note though, run 2 separate queries client, not want. want:

2. nest select in insert statement

dsl.using(conn)    .insertinto(calls)    .columns(calls.user_id, calls.call_link)    .values(        dsl.field(            dsl.select(users.id)               .from(users)               .where(users.oktell_login.equal(oktell_login))        )        , link    ).execute(); 

this same following single sql query:

insert calls (user_id, call_link) values ((select id users oktell_login = :oktell_login), :link) 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -